use httpx over requests

This commit is contained in:
steven 2025-05-10 21:50:27 -04:00
parent 0b8017cbc8
commit b8cb9881b3

8
app.py
View file

@ -1,14 +1,14 @@
from flask import Flask,render_template,send_from_directory
from flask_caching import Cache
import requests
import httpx
app=Flask(__name__)
app.config['CACHE_TYPE']='SimpleCache'
cache=Cache(app)
data=requests.get("https://tarc.rideralerts.com/InfoPoint/rest/Routes/GetVisibleRoutes").json()
data=httpx.get("https://tarc.rideralerts.com/InfoPoint/rest/Routes/GetVisibleRoutes").json()
routes=",".join(str(r.get("RouteId")) for r in data)
data=requests.get("https://tarc.rideralerts.com/InfoPoint/rest/Stops/GetAllStops").json()
data=httpx.get("https://tarc.rideralerts.com/InfoPoint/rest/Stops/GetAllStops").json()
stops={s.get("StopId"):[s.get("Latitude"),s.get("Longitude")] for s in data}
@app.route("/")
@ -18,5 +18,5 @@ def index():
@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=httpx.get("https://tarc.rideralerts.com/InfoPoint/rest/Vehicles/GetAllVehiclesForRoutes?routeIDs=0,"+routes).json()
return "\n".join(f"{v['Latitude']},{v['Longitude']},{v['RouteId']},{v['Name']},{v['OnBoard']},{v['DirectionLong']},{v['Speed']},{v['LastUpdated'][6:16]}" for v in d)