You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
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 = "Have you tried"
|
|
first_snack = True
|
|
for snack in snack_menu:
|
|
snack_title = snack["title"]
|
|
snack_price = snack["price"]
|
|
snack_category = findthecategory(snack)
|
|
happy_snack_image = has_snack_image(snack)
|
|
if not first_snack:
|
|
menu += "Or"
|
|
menu += f" *{snack_title}* from the menu section {snack_category} for the price of **{snack_price}** euros?"
|
|
first_snack = False
|
|
|
|
if happy_snack_image:
|
|
menu += "\r\n"
|
|
snack_img = snack["img_url"]
|
|
menu += f"\t{snack_img}"
|
|
menu += "\r\n\r\n"
|
|
return menu
|
|
|
|
print(menu())
|
|
|