Browse Source

snack becomes bot

main
crunk 4 weeks ago
parent
commit
1af8eda1d4
  1. 18
      requirements.txt
  2. BIN
      zulip_bots/bots/BotSpeciaal/__pycache__/botspeciaal.cpython-312.pyc
  3. BIN
      zulip_bots/bots/BotSpeciaal/__pycache__/snackfinder.cpython-312.pyc
  4. 15
      zulip_bots/bots/BotSpeciaal/botspeciaal.py
  5. 1
      zulip_bots/bots/BotSpeciaal/categories.json
  6. 1
      zulip_bots/bots/BotSpeciaal/products.json
  7. 53
      zulip_bots/bots/BotSpeciaal/snackfinder.py

18
requirements.txt

@ -0,0 +1,18 @@
beautifulsoup4==4.12.3
certifi==2024.8.30
charset-normalizer==3.4.0
click==8.1.7
distro==1.9.0
html2text==2024.2.26
idna==3.10
importlib_metadata==8.5.0
lxml==5.3.0
req==1.0.0
requests==2.32.3
six==1.16.0
soupsieve==2.6
typing_extensions==4.12.2
urllib3==2.2.3
zipp==3.20.2
zulip==0.9.0
zulip-bots==0.9.0

BIN
zulip_bots/bots/BotSpeciaal/__pycache__/botspeciaal.cpython-312.pyc

Binary file not shown.

BIN
zulip_bots/bots/BotSpeciaal/__pycache__/snackfinder.cpython-312.pyc

Binary file not shown.

15
zulip_bots/bots/BotSpeciaal/botspeciaal.py

@ -0,0 +1,15 @@
from snackfinder import menu
from typing import Any, Dict
from zulip_bots.lib import BotHandler
class AtoomSnackHandler:
def usage(self) -> str:
return ""
def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> None:
bot_handler.send_reply(message, menu())
handler_class = AtoomSnackHandler

1
zulip_bots/bots/BotSpeciaal/categories.json

@ -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
zulip_bots/bots/BotSpeciaal/products.json

File diff suppressed because one or more lines are too long

53
zulip_bots/bots/BotSpeciaal/snackfinder.py

@ -0,0 +1,53 @@
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())
Loading…
Cancel
Save