-
Notifications
You must be signed in to change notification settings - Fork 0
/
mealpingapi.py
66 lines (51 loc) · 1.9 KB
/
mealpingapi.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Install pyTelegramBotAPI using:
# pip install pyTelegramBotAPI
import requests
import telebot
API_KEY = "YOUR API TOKEN HERE"
bot = telebot.TeleBot(API_KEY)
base_mealdb_url = 'https://www.themealdb.com/api/json/v1/1/search.php'
rand_url = 'https://www.themealdb.com/api/json/v1/1/random.php'
@bot.message_handler(commands=['start'])
def msg(randomm):
bot.send_message(randomm.chat.id, "Try typing:\nMatar Paneer\n\nOr /random")
@bot.message_handler(commands=['random'])
def msg(randomm):
rand = requests.get(rand_url)
rand_json = rand.json()
for rnd in rand_json["meals"]:
data = "Making: {},\n\nSteps:\n {},\nImage: {}, \n\nYouTube Video: {}".format(
rnd["strMeal"],
rnd["strInstructions"],
rnd["strMealThumb"],
rnd["strYoutube"]
)
print(data)
bot.send_message(randomm.chat.id, data)
def recipe_request(mssg):
reqt = mssg.text.split()
if reqt[0].lower():
return True
else:
return
@bot.message_handler(func=recipe_request)
def send_recipe(mssg):
try:
reqt = mssg.text.split()
listToStr = ' '.join([str(elem) for elem in reqt])
query_params = "?s={}".format(listToStr)
final_url = base_mealdb_url + query_params
reps = requests.get(final_url)
reps_json = reps.json()
for meal in reps_json["meals"]:
data = "Making: {},\n\nSteps:\n {},\nImage: {}, \n\nYouTube Video: {}".format(
meal["strMeal"],
meal["strInstructions"],
meal["strMealThumb"],
meal["strYoutube"]
)
print(data)
bot.send_message(mssg.chat.id, data)
except:
bot.send_message(mssg.chat.id, "Sorry, No Recipes Found :( \nTry /random")
bot.polling()