From b06096039220b396155bc47b132d84b6eb4924dc Mon Sep 17 00:00:00 2001 From: steven Date: Tue, 27 May 2025 19:30:18 -0400 Subject: [PATCH] better stops (still WIP) --- app.py | 14 +++++--------- templates/map.html | 46 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/app.py b/app.py index 96b737d..5c34a94 100644 --- a/app.py +++ b/app.py @@ -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('/') +@app.route('/.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" diff --git a/templates/map.html b/templates/map.html index 9534cd3..8902c4e 100644 --- a/templates/map.html +++ b/templates/map.html @@ -9,28 +9,49 @@ - +