-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenuapp.py
More file actions
95 lines (80 loc) · 2.65 KB
/
menuapp.py
File metadata and controls
95 lines (80 loc) · 2.65 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import json
import datetime
import os
from flask import Flask
from flask import render_template
from flask import request
from key import APIKey
app = Flask(__name__)
@app.route('/')
@app.route('/index.html')
@app.route('/home')
@app.route('/index')
def showIndexPage():
return render_template('index.html')
@app.route('/hours')
def getHours():
if 'key' not in request.args or request.args['key'] != APIKey.key:
return "Wrong API key"
hoursFile = "./data/hours.json"
if os.path.exists(hoursFile) and os.path.isfile(hoursFile):
file = open(hoursFile, "r")
hoursJSON = file.read()
file.close()
return hoursJSON
@app.route('/quick')
def getQuickService():
if 'key' not in request.args or request.args['key'] != APIKey.key:
return "Wrong API key"
quickFile = "./data/quick.json"
if os.path.exists(quickFile) and os.path.isfile(quickFile):
file = open(quickFile, "r")
quickJSON = file.read()
file.close()
return quickJSON
@app.route('/menu-nutrition', methods=['GET'])
def getMenuWithNutrition():
if 'key' not in request.args or request.args['key'] != APIKey.keynu:
return "Wrong API key"
if ('year' in request.args) and ('month' in request.args) and ('day' in request.args):
year = request.args['year']
month = request.args['month']
day = request.args['day']
currentPath = "./menus-nutrition/"
dateNamePath = currentPath + year + "-" + month + "-" + day
# check if file exists yet
if os.path.exists(dateNamePath) and os.path.isfile(dateNamePath):
file = open(dateNamePath, "r")
menuJSON = file.read()
file.close()
return menuJSON
else:
empty = {"b":[],"l":[],"d":[]}
return json.dumps(empty, separators=(',',':'))
# bad parameters
else:
empty = {"b":[],"l":[],"d":[]}
return json.dumps(empty, separators=(',',':'))
@app.route('/menu', methods=['GET'])
def getMenus():
if 'key' not in request.args or request.args['key'] != APIKey.key:
return "Wrong API key"
if ('year' in request.args) and ('month' in request.args) and ('day' in request.args):
year = request.args['year']
month = request.args['month']
day = request.args['day']
currentPath = "./menus/"
dateNamePath = currentPath + year + "-" + month + "-" + day
# check if file exists yet
if os.path.exists(dateNamePath) and os.path.isfile(dateNamePath):
file = open(dateNamePath, "r")
menuJSON = file.read()
file.close()
return menuJSON
else:
empty = {"b":[],"l":[],"d":[]}
return json.dumps(empty, separators=(',',':'))
# bad parameters
else:
empty = {"b":[],"l":[],"d":[]}
return json.dumps(empty, separators=(',',':'))