-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipeDB.py
69 lines (53 loc) · 2.12 KB
/
recipeDB.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
67
68
import requests
api_key = "Bir8n5fgaMxbiDgm6fgQxGwvnpbjuzbKtP5dSZWccJumhMjd"
base = "https://apis-new.foodoscope.com/"
headers = {
'accept': 'application/json',
'Authorization': f'Bearer {api_key}'
}
def make_api_call(api_key, api_url, search_text, page_size):
params = {
'searchText': search_text,
'pageSize': page_size
}
try:
response = requests.get(api_url, headers=headers, params=params)
response.raise_for_status() # Raise an exception for 4xx and 5xx status codes
return response.json() # Parse response JSON
except requests.exceptions.RequestException as e:
print(f"Error making API call: {e}")
return None
def recipeInfo(recipe_id: int):
# Get the recipe information from the API
url: str = base + "recipe/" + str(recipe_id)
response = requests.get(url, headers=headers)
return response.json()["payload"]
def searchBySubRegion(sub_region: str):
# Get recipes by sub-region
url: str = f"https://cosylab.iiitd.edu.in/api/recipeDB/searchBySubRegion/{sub_region}"
payload, headers = {}, {}
response = requests.request("GET", url, headers=headers, data=payload)
return response.json()
def searchRegion(region: str):
# Get recipes by region
url: str = f"https://cosylab.iiitd.edu.in/api/recipeDB/searchRegion/{region}"
payload, headers = {}, {}
response = requests.request("GET", url, headers=headers, data=payload)
return response.json()
def getIngredientsByRecipeId(recipe_id: int):
# Get ingredients by recipe id
url: str = f"https://cosylab.iiitd.edu.in/api/recipeDB/getIngredientsByRecipeId/{recipe_id}"
payload, headers = {}, {}
response = requests.request("GET", url, headers=headers, data=payload)
return response.json()
def recipeOfTheDay():
# Get the recipe of the day
url: str = base + "recipe/recipeOftheDay"
try:
response = requests.get(url, headers=headers)
print(response.raise_for_status())
print(response.raw)
return response.json()
except requests.exceptions.RequestException as e:
print(e)
return None