-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstops_for_location.py
45 lines (35 loc) · 1.33 KB
/
stops_for_location.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from typing import Any
from helpers.load_env import load_settings
from onebusaway import OnebusawaySDK
# Load settings from .env file, if it exists. If not, we'll use the
# Puget Sound server URL (which is also the default in the SDK) and
# the 'TEST' API key.
settings = load_settings(
{
"api_key": "TEST",
"base_url": "https://api.pugetsound.onebusaway.org/",
}
)
# Create a new instance of the OneBusAway SDK with the settings we loaded.
oba = OnebusawaySDK(**settings)
space_needle_stops = oba.stops_for_location.list(
lat=47.6205,
lon=-122.3493,
)
stops = space_needle_stops.data.list
references = space_needle_stops.data.references
# make it easy to look up routes by ID.
reference_map = {}
for ref_route in references.routes:
reference_map[ref_route.id] = ref_route
for stop in stops:
print(f"{stop.name} ({stop.lat}, {stop.lon})")
print(" Routes:")
for route_id in stop.route_ids:
# TODO: add type to route
route: Any = reference_map[route_id]
# Get a string that looks like "D Line - Blue Ridge/Crown Hill - Ballard - Downtown Seattle"
description_list = [route.null_safe_short_name, route.description]
description_list = [e for e in description_list if e]
description_str = " - ".join(description_list)
print(f" {description_str}")