forked from ju135/HeinzBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spoonacular_bot.py
34 lines (28 loc) · 1.3 KB
/
spoonacular_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import requests
import telegram
from telegram import Update
from telegram.ext import CallbackContext
from utils import api_key_reader
from modules.abstract_module import AbstractModule
from utils.decorators import register_module, register_command
@register_module()
class SpoonacularBot(AbstractModule):
url = "https://api.spoonacular.com/"
@register_command(command="meals",
short_desc="Returns random meal recipes to cook. 👨🍳🍽",
long_desc="Uses the spoonacular api in order to find 4 random meals and"
"returns them.",
usage=["/meals"])
def random_receipt(self, update: Update, context: CallbackContext):
chat_id = self.get_chat_id(update)
key = api_key_reader.read_key("spoon")
extender = "{}recipes/random?apiKey={}&number=4".format(self.url, key)
data = requests.get(extender)
jsonData = json.loads(data.text)
response = "Meals I found randomly \n"
for recipe in jsonData['recipes']:
response += "*" + recipe['title'] + "*" + "\n"
response += recipe['sourceUrl'] + "\n"
response += "\n"
context.bot.send_message(chat_id=chat_id, text=response, parse_mode=telegram.ParseMode.MARKDOWN)