Menu

The Menu class represents the full weekly menu, and it has a list of Day objects, that represents the menu for individual days. It has everything that's needed to get and parse menu data for the current week.

class Menu (object)

Variables

Please note: When a variable is not available, it has the value "None". A successful execution of the get_menu()-function should make all variables available. All variables listed below will have None as a value by default.

entries (list) - contains Day objects with menu information for each day of the week or an empty list if the week menu has not been retrieved yet. See Day.

image (dict) - contains image data of the menu image if it has been retrieved. Keys: "raw" and "ocr" with either None (image has not retrieved) or bytes (it has been retrieved) versions of the image.

week (int) - an integer of the current week number

retrieved_week (int) - an integer of what week the menu was retrieved

schema_version (int) - the schema version that the API response follows

menu_json (dict) - the raw JSON from the API response (however, loaded as a dict). To get it back to raw JSON for usage outside the script, simply use json.dumps() in Python.

last_retrieved (dict) - a dict with keys that is used for the internal "cache" of menu items. The keys store datetime objects of the last retrieval.

menu_last_sent (datetime) - Stores when the menu was last sent to the user. Used by the wait_for_update function

Functions

Initialization (__init__)

This function takes no optional arguments.

initialize()

Required if you want to retrieve "regular" menu data (not images). You need to call this before everything else that interfaces with the Websocket API (which is everything but images). Executes for maximum 30 seconds, and if no connection has been established after that, an InitializationTimeout exception is raised.

The function takes the following arguments:

subscribe_to (string, default: "all") - Choose with menu events to subscribe to. See the example on this page.

Log (boolean, default: False) - If True, a detailed websocket log will be shown.

get_menu

This is the go-to function that returns the week menu in form of a list with parsed items as Day objects, or a menu image. The function takes 4 optional arguments:

image (boolean, default: False) - If True, the function will return raw bytes of the latest menu image. If it is False, it will return parsed menu data in the format of parsed Day objects.

image_type (string, default: "raw") - Only applicable when retrieving an image. The image type, either "raw" (the raw menu image) or "ocr" (the image that was converted to when OCR-scanning the menu).

force_request (boolean, default: False) - Only used when returning images. If True, the library will send a new request to the Lunchbot API server every time you want to retrieve an image. If not, it will use the cache (see here for more information)

timeout (int, default: 30) - The timeout for the function. If no data is returned after the timeout has exceeded, an InitializationTimeout exception will be raised.

wait_for_menu_update

Function for waiting until the next menu update. Interrupts your program - does not run in the background.

Internal functions

These functions are not advised to be called by you. The program already calls all of them when interacting with the function s that you are supposed to interact with.

retrieve_menu_image

This function retrieves the menu image from either the cache or the Lunchbot server.

parse_menu

This function takes one argument, the raw JSON returned by the Lunchbot API, and converts it into "Day" classes, which is returned. The parse_menu function is obviously not recommended to be called. Instead, call get_menu.

_wait for_connect

Internal function with timeout support for waiting until a websocket has been established.

_wait for_menu

Internal function with timeout support for waiting until a menu has been received for the first time.

Last updated

Was this helpful?