-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
28 lines (20 loc) · 779 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
from flask import Flask, Response, render_template
import json
import requests
import requests_cache
import os
QUERY_URL = 'https://api.jcdecaux.com/vls/v1/stations?contract=Vilnius&apiKey=%s'
API_KEY = os.getenv('JCD_API_KEY')
if not API_KEY:
raise Exception('''No JCDecaux API key was supplied''')
app = Flask(__name__, static_url_path='/static')
requests_cache.install_cache(cache_name='jcdecaux_cache', backend='sqlite', expire_after=180)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/apidata')
def jcdecaux_cycledata():
r = requests.get(QUERY_URL % API_KEY)
return Response(json.dumps(r.json()), mimetype='application/json')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.getenv('PORT', '5000')))