-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApi_Request.py
71 lines (55 loc) · 2.14 KB
/
Api_Request.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
import requests
from Methods import Methods
import time
class Api_Request:
def __init__(self, recipe):
self.recipe = recipe
self.methods = Methods()
self.url = f"https://api.api-ninjas.com/v1/recipe?query={self.recipe}"
self.apikey = "WvN7UBmzmUbNYSMYEGqNdg40eJ3p199mYTwHnc1J"
try:
response = requests.get(self.url, headers={"X-Api-Key": self.apikey})
self.data = response.json()
if response.status_code != 200:
print(f"Error fetching data. Status code: {response.status_code}")
except requests.RequestException as e:
print(f"Error fetching data: {e}")
self.data = {}
def showTitles(self):
for idx, obj in enumerate(self.data):
self.methods.spacer()
print(f"{idx} - {obj['title']}")
self.methods.spacer()
def showRecipe(self,isDataAvailable=False):
if (isDataAvailable):
for recipe in isDataAvailable:
self.methods.spacer()
print(isDataAvailable["title"])
self.methods.spacer()
print(isDataAvailable["instructions"])
self.methods.spacer()
print(isDataAvailable["ingredients"])
self.methods.spacer()
print("Status : 2")
print(time.ctime())
else:
for recipe in self.data:
self.methods.spacer()
print(recipe["title"])
self.methods.spacer()
print(recipe["instructions"])
self.methods.spacer()
print(recipe["ingredients"])
self.methods.spacer()
print("Status : 2")
print(time.ctime())
def returnRecipe(self):
data = {}
for recipe in self.data:
data[recipe['title']] = {
'instruction': recipe['instruction'],
'ingredients': recipe['ingredients'],
'status': recipe['status'],
'time': recipe['time']
}
return data