-
Notifications
You must be signed in to change notification settings - Fork 6
/
retrieve_recipes.py
64 lines (49 loc) · 1.62 KB
/
retrieve_recipes.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
# recipe.hyeungshikjung.com/recipe/trees/potatosalad
# ~/recipe/recipe/<id> : get recipe using id
# ~/recipe/recipes/<dishname>: get all the recipes of dish (currently only ‘potatosalad’ is available)
# ~/recipe/clusters/<dishname>: get all clustering result of dish
import json
import requests
import pprint as pp
servername = "http://recipe.hyeungshikjung.com/"
# dishname = "potatosalad"
# recipeid = ""
def get_recipes_json(dishname):
#getting annotated text instructions for all recipes for dishname
try:
r = requests.get(servername+"recipe/recipes/"+dishname)
r.raise_for_status()
except requests.exceptions.HTTPError as err:
print(err)
sys.exit(1)
#recipes = r.json()
#pp.pprint(recipes)
return r.json()
def get_all_recipes(dishname):
#getting annotated text instructions for all recipes for dishname
try:
r = requests.get(servername+"recipe/trees/"+dishname)
r.raise_for_status()
except requests.exceptions.HTTPError as err:
print(err)
sys.exit(1)
#recipes = r.json()
#pp.pprint(recipes)
return r.json()
def get_single_recipe(recipeid):
#getting a single recipe
try:
r = requests.get(servername+"recipe/recipe/"+recipeid)
r.raise_for_status()
except requests.exceptions.HTTPError as err:
print(err)
sys.exit(1)
return r.json()
def get_clusters(dishname):
try:
r = requests.get(servername+"recipe/clusters"+dishname)
r.raise_for_status()
except requests.exceptions.HTTPError as err:
print(err)
sys.exit(1)
return r.json()