-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-io.py
38 lines (30 loc) · 953 Bytes
/
json-io.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
import json
import scraper
def saveAsJSON(filename, lib):
f = open(filename, "w")
f.write(json.dumps(lib, sort_keys=True, indent=4))
f.close()
def readJSON(filename):
f = open(filename, "r")
data = json.load(f) #dictionary
# Checking content
mandatory_keys = ['lunch', 'dinner']
for key in mandatory_keys:
if key not in data:
raise ValueError("Cannot find '" + key + "'")
lunch = data['lunch']
dinner = data['dinner']
print("\tMidi : " + lunch + ",\n\tSoir : " + dinner)
def updateMenus():
res = scraper.main()
for restaurant in res.keys():
saveAsJSON(restaurant+".json", res[restaurant])
def loadMenu(restaurant):
print(restaurant + " - ")
readJSON(restaurant+".json")
def loadAll():
restaurants = ["Capu", "Mascaret", "RU1", "RU2", "Space Campus", "Veracruz"]
for restaurant in restaurants:
loadMenu(restaurant)
updateMenus()
loadAll()