-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
51 lines (39 loc) · 1.32 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
42
43
44
45
46
47
48
49
50
51
import os
from dotenv import load_dotenv
from flask import Flask, request, render_template, jsonify
from src.attributes.attr_get import Attributes
from src.attributes.osm import OSM
from src.attributes.weather import WeatherAttr
load_dotenv()
app = Flask(__name__)
weatherAPI = WeatherAttr()
osmAPI = OSM()
attributesAPI = Attributes()
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
@app.route('/api/attributes', methods=['GET'])
def get_attributes():
return jsonify(attributesAPI.get_attributes())
@app.route('/api/<attributes>', methods=['GET'])
def get_data(attributes):
if attributes == 'weather':
return {
'data': weatherAPI.get_data(
request.args.get('lat', 0),
request.args.get('lon', 0),
request.args.get('distance', 40),
request.args.get('attribute', 'sun'))
}
else:
return {
'data': osmAPI.get_data(
request.args.get('attribute', 'bread'),
request.args.get('time', 0),
request.args.get('lat', 0),
request.args.get('lon', 0),
request.args.get('distance', 40)
)
}
if __name__ == '__main__':
app.run(debug=os.getenv('DEBUG_MODE', False), port=os.getenv('PORT', 5000))