mvg
mvg copied to clipboard
nearest station based on transport type
What would also be nice is to get the nearest station based on the station type. For example, the nearest SBAHN station. Something like this maybe:
async def nearby_async(latitude: float, longitude: float, transport_type: TransportType = None) -> dict[str, str] | None:
try:
args = dict.fromkeys(Endpoint.FIB_NEARBY.value[1])
args.update({"latitude": latitude, "longitude": longitude})
result = await MvgApi.__api(Base.FIB, Endpoint.FIB_NEARBY, args)
assert isinstance(result, list)
# return first location of type "STATION"
for location in result:
if transport_type == None:
station = {
"id": location["globalId"],
"name": location["name"],
"place": location["place"],
}
return station
elif str(transport_type.name) in location["transportTypes"]:
station = {
"id": location["globalId"],
"name": location["name"],
"place": location["place"],
}
return station
# return None if no station was found
return None
Originally posted by @jannikobenhoff in https://github.com/mondbaron/mvg/issues/3#issuecomment-1633197662