-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (42 loc) · 1.18 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
52
53
54
55
56
import os, redis
from flask import Flask, redirect, request
from locache.root import Endpoint
from flask.ext.cors import CORS
r = redis.from_url(os.environ.get('REDIS_URL'))
app = Flask(__name__)
CORS(app)
@app.route('/info')
def info():
return """
<p>main-endpoint:
<a href='/'>
locache.herokuapp.com/?{location[, timestamp]}
</a>
</p>
<p>docs (apiary.io):
<a href='/docs'>
locache.herokuapp.com/docs
</a>
</p>
<p>github:
<a href='https://github.com/stevenpollack/locache'>
https://github.com/stevenpollack/locache
</a>
</p>
"""
@app.route('/docs')
def route_to_apiary():
apiary_io = 'http://docs.locache.apiary.io/'
return redirect(apiary_io, code=302)
@app.route('/', methods=['GET'])
def get_tz_info():
if len(request.args) == 0:
return redirect('/info')
location = request.args.get('location')
timestamp = request.args.get('timestamp')
endpoint = Endpoint(location, timestamp, r)
if endpoint.query_cache():
return endpoint.response
return endpoint.fetch_info_and_populate_cache()
if (__name__ == '__main__'):
app.run(debug=True, host='0.0.0.0', port=5000)