implement flask caching
This commit is contained in:
parent
0db90601d9
commit
e4bd7da77f
2 changed files with 9 additions and 8 deletions
9
app.py
9
app.py
|
@ -1,10 +1,14 @@
|
|||
from flask import Flask, jsonify, render_template, send_from_directory
|
||||
from flask_caching import Cache
|
||||
import requests
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
app.config['CACHE_TYPE'] = 'SimpleCache'
|
||||
cache = Cache(app)
|
||||
|
||||
data=requests.get("https://tarc.rideralerts.com/InfoPoint/rest/Routes/GetVisibleRoutes").json()
|
||||
routes = ",".join(str(r.get('RouteId')) for r in data)
|
||||
routes=",".join(str(r.get('RouteId')) for r in data)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
|
@ -15,8 +19,9 @@ def favicon():
|
|||
return send_from_directory(app.static_folder,"bus.svg")
|
||||
|
||||
@app.route('/tarc.csv')
|
||||
@cache.cached(timeout=5)
|
||||
def tarc():
|
||||
d=requests.get("https://tarc.rideralerts.com/InfoPoint/rest/Vehicles/GetAllVehiclesForRoutes?routeIDs=0,"+routes).json()
|
||||
d=requests.get("https://tarc.rideralerts.com/InfoPoint/rest/Vehicles/GetAllVehiclesForRoutes?routeIDs="+routes).json()
|
||||
return "\n".join(f"{v['Latitude']},{v['Longitude']},{v['RouteId']},{v['Name']},{v['OnBoard']},{v['DirectionLong']},{v['Speed']}" for v in d)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue