implement flask caching
This commit is contained in:
parent
0db90601d9
commit
e4bd7da77f
2 changed files with 9 additions and 8 deletions
7
app.py
7
app.py
|
@ -1,8 +1,12 @@
|
|||
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)
|
||||
|
||||
|
@ -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__':
|
||||
|
|
|
@ -9,11 +9,7 @@
|
|||
<link rel="icon" type="image/x-icon" href="/bus.svg">
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
|
||||
<style>
|
||||
html,body{height:100%;margin:0;}
|
||||
#map{height:100vh;}
|
||||
#clock{background-color:black;color:white;font:16px monospace;}
|
||||
</style>
|
||||
<style>html,body{height:100%;margin:0;}#map{height:100vh;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
|
@ -30,7 +26,7 @@ function updateMap() {
|
|||
})
|
||||
})
|
||||
}
|
||||
setInterval(updateMap,5000); // use websocket
|
||||
setInterval(updateMap,5000);
|
||||
|
||||
let locationMarker=L.marker([0,0]),locationRadius=L.circle([0,0]);
|
||||
let locationLayer=L.layerGroup([locationMarker,locationRadius]).addTo(map);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue