-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
39 lines (31 loc) · 955 Bytes
/
app.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
from flask import Flask
from flask import request, jsonify
from webscraper import scrape, scrapeAll, scrapeById, scrapeForFoods
import os
app = Flask(__name__)
MENUS = {}
FOOD_DICT = {}
@app.route('/', methods=['GET'])
def home():
global FOOD_DICT
MENUS, FOOD_DICT = scrapeForFoods()
return jsonify(Data=MENUS)
@app.route('/foods/all', methods=['GET'])
def all():
return jsonify(Data=FOOD_DICT)
@app.route('/foods', methods=['GET'])
def id():
if 'id' in request.args:
id=request.args['id']
if(FOOD_DICT.get(id) != None):
return jsonify(Data=scrapeById(FOOD_DICT, id))
else:
return "<h1>Food Item not found</h1>"
else:
return "<h1>Error: No id field provided. Please specify an id.</h1>"
@app.errorhandler(404)
def page_not_found(e):
return "<h1>404</h1><p>The resource could not be found.</p>", 404
port = int(os.environ.get("PORT", 5000))
if __name__ == "__main__":
app.run(threaded=True, port=port)