forked from k-nut/markt-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (32 loc) · 1.22 KB
/
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
40
41
#/usr/bin/env python3
""" The main app. It contains all the routes """
import json
from flask import Flask, request, jsonify
import controller
app = Flask(__name__) # pylint: disable=invalid-name
@app.route('/routes')
def get_routes():
""" Returns a list of api endpoints """
return controller.get_routes()
@app.route('/open_at')
def open_at():
""" Returns a geojson representation of markets that are open at
the given date and time for the given city """
cities = controller.get_cities()
city = request.args.get('city', None)
if (city is None) or (city.lower() not in cities):
return json.dumps({"message": "city %s not found" % city}), 404
else:
data = controller.get_data_for(city)
day = request.args.get("day", None)
time = request.args.get("time", None)
if day is not None and time is not None:
days = ["mo", "tu", "we", "th", "fr", "sa", "su"]
if day not in days:
message = "Parameter day must be one of " + str(days)
return json.dumps({"message": message}), 400
data["features"] = controller.filter_by(data["features"], day, time)
return jsonify(data)
if __name__ == '__main__':
app.debug = True
app.run()