snack selectors

This commit is contained in:
crunk 2024-11-08 18:36:41 +01:00
commit e00ab6be6e
4 changed files with 52 additions and 0 deletions

1
basicinfo.json Normal file

File diff suppressed because one or more lines are too long

1
categories.json Normal file
View File

@ -0,0 +1 @@
[{"usedAt":[],"_id":"61d09ea9436e2474f4269035","cat_code":"cat1","cat_name":"Actie's","sort_number":1,"cat_description":""},{"usedAt":[],"group_items":[],"_id":"5fb2989e4c74b862a5a8c70d","cat_code":"cat2","cat_name":"Populair gerechten","sort_number":2},{"usedAt":[],"_id":"60181524f823670165a7cdf9","cat_code":"cat3","cat_name":"Schotels","sort_number":4,"cat_description":""},{"usedAt":[],"_id":"64459be7fb649c277ff2a3cd","cat_code":"cat4","cat_name":"Atoom keuze menu","sort_number":5,"cat_description":"","image_link":"."},{"usedAt":[],"_id":"60181533f823670165a7cdfa","cat_code":"cat5","cat_name":"Patat & Snacks","sort_number":3,"cat_description":""},{"usedAt":[],"_id":"61d09f04436e2474f42690a9","cat_code":"cat6","cat_name":"Belegde broodjes","sort_number":9,"cat_description":""},{"usedAt":[],"group_items":[],"_id":"5fb30a521daa333b1e53c257","cat_code":"cat7","cat_name":"Stokbrood","sort_number":10},{"usedAt":[],"group_items":[],"_id":"5fb30a501daa333b1e53c256","cat_code":"cat8","cat_name":"Soepen & Voor gerechten","sort_number":11},{"usedAt":[],"group_items":[],"_id":"5fb30a491daa333b1e53c255","cat_code":"cat9","cat_name":"Nasi & Bami & Mihoen","sort_number":12},{"usedAt":[],"group_items":[],"_id":"5fb3fc9a1daa333b1e53c2a9","cat_code":"cat10","cat_name":"Eieren & Groenten gerechten","sort_number":13},{"usedAt":[],"group_items":[],"_id":"5fb30a441daa333b1e53c253","cat_code":"cat11","cat_name":"Vlees & Kip gerechten","sort_number":14},{"usedAt":[],"group_items":[],"_id":"5fb2f02c1daa333b1e53c215","cat_code":"cat12","cat_name":"Combi gerechten","sort_number":15},{"usedAt":[],"group_items":[],"_id":"5fb2f0291daa333b1e53c214","cat_code":"cat13","cat_name":"Sauzen","sort_number":16},{"usedAt":[],"group_items":[],"_id":"5fb2f0261daa333b1e53c213","cat_code":"cat14","cat_name":"Dranken","sort_number":17},{"usedAt":[],"group_items":[],"_id":"5fb2f0231daa333b1e53c212","cat_code":"cat15","cat_name":"Milkshake's","sort_number":18},{"usedAt":[],"_id":"6018151af823670165a7cdf7","cat_code":"cat16","cat_name":"Surinaamse broodjes, telo en bara","sort_number":6,"cat_description":""},{"usedAt":[],"_id":"60181515f823670165a7cdf6","cat_code":"cat17","cat_name":"Surinaamse maaltijden","sort_number":7,"cat_description":""},{"usedAt":[],"_id":"60181511f823670165a7cdf5","cat_code":"cat18","cat_name":"Specialiteiten","sort_number":8,"cat_description":""}]

1
products.json Normal file

File diff suppressed because one or more lines are too long

49
snackfinder.py Normal file
View File

@ -0,0 +1,49 @@
import json
import random
products = "products.json"
categories = "categories.json"
def findthesnacks(products):
"""these are the snacks you are looking for"""
with open(products, 'r') as snacks:
snackdata = json.load(snacks)
return random.choice(snackdata)
def munchies(amount):
snack_menu = []
for _ in range(amount):
snack_menu.append(findthesnacks(products))
return snack_menu
def findthecategory(snack):
snack_category = snack["categorie"][0]
with open(categories, 'r') as category_json:
categorydata = json.load(category_json)
for category in categorydata:
if category["cat_code"] == snack_category:
return category["cat_name"]
def has_snack_image(snack):
return "img_url" in snack
def menu():
snack_menu = munchies(3)
menu = ""
for snack in snack_menu:
snack_title = snack["title"]
snack_price = snack["price"]
snack_category = findthecategory(snack)
happy_snack_image = has_snack_image(snack)
menu += f"Have you tried {snack_title} from the menu section {snack_category} for the price of {snack_price} euros"
if happy_snack_image:
menu += "\r\n"
snack_img = snack["img_url"]
menu += f"[An image of {snack_title}]({snack_img})"
menu += "\r\n"
return menu
print(menu())