burgoking

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 15 Imported by: 0

README

burgoking

⚠️ As of September 2022, Burger King migrated their survey system to a third party company, resulting to changes that require an almost complete rebuild of this project. Unfortunately, I cannot find the time nor the will to do it. So, I replaced the generation algorithm with something local and static. In almost all cases, this generator will work (I never encountered a BK employee that checked the numbers). ⚠️

🍔 Burger King - Free Burger Code Generator 🍔

Generate a Burger King's promotion code to get a free burger using Golang.

Installation

$ go get github.com/scotow/burgoking

Examples
Library

The library provides two ways to generate codes. A single code can be generating or an auto refreshing pool can be used.

Generating a single code
func GenerateCode(meal *Meal) (code string, err error)

The meal argument is used to fill the first page of the survey.

type Meal struct {
	Restaurant int
	Date       time.Time
}

Passing nil as an argument generate a random meal using the func RandomMeal() *Meal function.

Using a pool of codes

A pool of codes holds a fixed amount of codes. When a code of the pool is consumed by the function GetCode, a new goroutine is spawned to generate a new code.

An expiration duration can be specified. When a code has stayed in the pool for too long, a timer removes it from the pool and a new generation is launched.

To create a new pool, you may call the following function:

func NewPool(size int, expiration, retry time.Duration) (pool *Pool, err error)

Where

  • size is the total number of codes in the pool.
  • expiration is the duration required for a code to be remove and auto re-generated.
  • retry is the duration required between two calls of the GenerateCode function if the first call failed for any reason. This prevents the pool from spaming the website.
Binaries

The cmd folder contains three examples of program that use the burgoking library.

Simple code

The code command is a simple wrapper of the library. It generates a code and prints it to stdout.

Here are the available options:

Usage of code:
  -n int
    	number of code to generate (default 1)
  -p	
  	generate each code on a different goroutine (default false)
Simple API

The api command starts a simple web server that returns a new promotion code to each request.

(Old) Web friendly server

The web command is a ready-for-demo binary that serves a simple, yet beautiful UI generating promotion codes using a pool.

The program may setup a second private pool that requires a Authorization HTTP header.

Here are the available options:

Usage of web:
  -D string
    	private code expiration (default "24h0m0s")
  -N int
    	private code pool size (default 1)
  -R string
    	private code regeneration interval (default "30s")
  -c string
    	contact address on error
  -d string
    	public code expiration (default "24h0m0s")
  -k string
    	authorization token for private and direct code (disable if empty)
  -n int
    	public code pool size (default 3)
  -p int
    	listening port (default 8080)
  -r string
    	public code regeneration interval (default "30s")
Contribution

Feedback are appreciated. Feel free to open an issue or a pull request if needed.

Furthermore, if you went to restaurant which its number isn't in the restaurants list, a merge request to add it is appreciated.

Disclaimer

burgoking provided by Scotow is for illustrative purposes only which provides customers with programming information regarding the products. This software is supplied "AS IS" without any warranties and support.

I assumes no responsibility or liability for the use of the software, conveys no license or title under any patent, copyright, or mask work right to the product.

JavaScript version

A deprecated and no more maintained version of this project made with JavaScript (NodeJS) and CasperJS is availiable here.

Enjoy your meal!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAPIResponse = errors.New("invalid response from the website")
	ErrFormNotFound       = errors.New("cannot find form from the response")
	ErrInvalidCode        = errors.New("cannot parse code from the page")
	ErrTooManyRequest     = errors.New("too many requests")
	ErrInvalidIndex       = errors.New("cannot find index from value")
)
View Source
var (
	InvalidPoolSettings = errors.New("invalid pool settings")
)
View Source
var (
	RestaurantCodes = []int{

		1677,
	}
)

Functions

func GenerateCode

func GenerateCode(meal *Meal) (code string, err error)

func GenerateCodeStatic added in v1.2.0

func GenerateCodeStatic(meal *Meal) (code string, err error)

Types

type Meal

type Meal struct {
	Restaurant int
	Date       time.Time
}

func RandomMeal

func RandomMeal() *Meal

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(size int, expiration, retry time.Duration) (pool *Pool, err error)

func (*Pool) GetCode

func (p *Pool) GetCode(codeC chan<- string, cancelC <-chan struct{})

Directories

Path Synopsis
cmd
api
web

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL