Usage Examples

Here are some further usage examples for the library.

Websockets quickstart example

The full quickstart example for Websockets (also shown here).

"""Websocket/API example
This example shows you the "standard" way of getting the week
menu, which will return a parsed list of Day objects.
NOTE: Want to do this with less code?
Check the compact example."""
from eatery_nod import EateryNod #Import the library
menu = EateryNod.Menu() #Create a menu object
menu.initialize() #Initialize (this is only required when using WebSockets)
print("Retrieving menu...") #Print out the status
week_menu = menu.get_menu() #Get the menu
for day in week_menu: #Loop through all the days in the menu
    menu_items_str = "\n".join(day.menu_items) #Format the menu items to a pretty string as they are returned as a list
    print(day.day_name_sv) #Print out the day name (in Swedish)
    print(menu_items_str) #Print out the menu items
    print("Day information:") #Print out a nice divider
    print("Date: " + str(day.day_date)) #Print out the day date
    print("Dessert served?: " + str(day.dessert_served)) #Print out if dessert is served (this will print either True or False)
    print("Pancakes served?: " + str(day.pancakes_served)) #Print out if pancakes are served (this will print either True or False)
    print("Hamburgers served?: " + str(day.burgers_served)) #Print out if hamburgers are served (this will print either True or False)
    print("---------------------------------------------------") #Print out a divider line
last_retrieved = menu.last_retrieved["json"] #Get when the menu was last retrieved
print("Menu retrieved: " + str(last_retrieved)) #Print out when the menu was last retrieved.

Websockets quickstart compact example

A more compact version of the code above.

"""Websocket/API compact example
This example shows you the "standard" way of getting the week
menu, which will return a parsed list of Day objects.
NOTE: Want to do see more detailed and formatted code?
Check the regular websocket example."""
from eatery_nod import EateryNod #Import the library
menu = EateryNod.Menu() #Create a menu object
menu.initialize() #Initialize (this is only required when using WebSockets)
print("Retrieving menu...")
week_menu = menu.get_menu() #Get the menu
for day in week_menu: #Loop through all the days in the menu
    menu_items_str = "\n".join(day.menu_items) #Format the menu items to a pretty string as they are returned as a list
    print(day.day_name_sv) #Print out the day name (in Swedish)
    #Print out everything. On one line, but might take a bit longer to grasp than the regular example.
    print(f"{day.day_name_sv} ({day.day_name}) \n{menu_items_str}\nDate:: {str(day.day_date)}, Dessert is served: {str(day.dessert_served)}. Pancakes are served: {str(day.pancakes_served)}. Hamburgers are served: {str(day.burgers_served)}\n----------------------------------------")
last_retrieved = menu.last_retrieved["json"] #Get when the menu was last retrieved
print(f"Menyn hÀmtades {last_retrieved}") #Print out when the menu was last retrieved.

Images quick example

A quick usage example for using the library to retrieve and save an image of the current week menu image. This does not require or use the Websocket interface.

"""Image.py
Quick example for getting the weekly Eatery menu image from the API.
This example returns and saves the image in its original format, which
is PNG."""
from eatery_nod import EateryNod #Import the library
menu = EateryNod.Menu() #Initialize a menu object
data = menu.get_menu(image=True) #Get the image data (in bytes format)
open(f"{menu.week}.png", "w").write(data) #Open a file and save the image data to it.

Last updated

Was this helpful?