-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode
More file actions
40 lines (31 loc) · 1.08 KB
/
code
File metadata and controls
40 lines (31 loc) · 1.08 KB
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
import requests
def recipe_search(ingredient):
# Register to get an APP ID and key https://developer.edamam.com/
app_id = ' '
app_key = ' '
result = requests.get(
'https://api.edamam.com/search?q={}&app_id={}&app_key={}'.format(ingredient, app_id, app_key)
)
data = result.json()
return data['hits']
print(recipe_search("salt"))
def run():
ingredient = input('Enter an ingredient: ')
results = recipe_search(ingredient)
recipe_list=[]
for result in results:
recipe = result['recipe']
calories = int(recipe["calories"])
recipe_list.append(calories)
sorted(recipe_list)
print(recipe['label'])
print(recipe['uri'])
print(int(recipe["calories"]))
print()
# to save into a txt file
with open("recipes.txt", "w+") as text_file:
for result in results:
text_file.write(str(result["recipe"]["label"])+"\n")
text_file.write(str(result["recipe"]["uri"])+"\n")
text_file.write(str(result["recipe"]["calories"]) + "\n")
run()