better stops (still WIP)

This commit is contained in:
steven 2025-05-27 19:30:18 -04:00
parent 0f5f878485
commit b060960392
2 changed files with 37 additions and 23 deletions

14
app.py
View file

@ -22,7 +22,7 @@ def tarc():
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['Destination']},{v['Heading']},{v['Speed']},{v['DirectionLong']},{v['LastUpdated'][6:16]}" for v in d)
@app.route('/<int:stop>')
@app.route('/<int:stop>.csv')
@cache.cached(timeout=5)
def stop(stop):
if stop not in stops:return "not a stop"
@ -30,14 +30,10 @@ def stop(stop):
if response.status_code==200:
table=BeautifulSoup(response.content,"html.parser").find("table")
if table:
table.attrs={}
for element in table.find_all(True):
if element.name in ["div","a"]:element.unwrap()
else:element.attrs={}
for element in table.find_all(["th","td"]):
element.string=element.get_text(strip=True)
return render_template("stop.html",table=str(table))
return render_template("stop.html",table="".join(str(table).split("\n")))
csv=[",".join([h.get_text(strip=True) for h in table.find_all("th")])]
for row in table.find_all("tr")[1:]:
csv.append(",".join([c.get_text(strip=True) for c in row.find_all("td")]))
return "\n".join(csv)
else:
return "no stop information"
return "fetch failed"