-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransform.py
41 lines (36 loc) · 1.17 KB
/
transform.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
import os
import json
from nutrition import NutritionParser
file = open('./data/quick.json', 'r')
quickJSON = file.read()
file.close()
quick = json.loads(quickJSON)
for key, menu in quick.items():
for k in range(0, len(menu)):
kitchen = menu[k]
for i in range(1, len(kitchen)):
section = kitchen[i]
for j in range(2, len(section)):
entree = section[j]
recipe = entree[3]
if recipe and len(recipe) == 6:
nutritionPath = './nutrition/' + recipe
nutrition = []
if os.path.exists(nutritionPath) and os.path.isfile(nutritionPath):
file = open(nutritionPath, 'r')
nutritionJSON = file.read()
file.close()
nutrition = json.loads(nutritionJSON)
else:
parser = NutritionParser(recipe)
nutritionJSON = parser.downloadNutritionData(shouldSave=True)
nutrition = json.loads(nutritionJSON)
quick[key][k][i][j][3] = nutrition
# print(entree)
else:
os.exit(1)
print(quick)
quickJSON = json.dumps(quick, separators=(',',':'))
file = open('./data/quick.min.json', 'w')
file.write(quickJSON)
file.close()