mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: improved station selection
This commit is contained in:
@@ -30,10 +30,8 @@ except:
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
TODO
|
TODO
|
||||||
- 1024 embed limit
|
|
||||||
- discord status
|
- discord status
|
||||||
- text announcements
|
- config cleanup
|
||||||
- voice announcements
|
|
||||||
- multi language support
|
- multi language support
|
||||||
- README
|
- README
|
||||||
'''
|
'''
|
||||||
+16
-9
@@ -27,22 +27,30 @@ def get_random_stop_id() -> str | None:
|
|||||||
logger(f"An error occured while searching for a connection: {e}", "error")
|
logger(f"An error occured while searching for a connection: {e}", "error")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if response.status_code == 404:
|
stop_ids = {}
|
||||||
logger(f"Error finding station '{assigned_station}'", "error")
|
|
||||||
return None
|
|
||||||
|
|
||||||
id = None
|
|
||||||
for entry in data:
|
for entry in data:
|
||||||
if entry.get("type") != "STOP":
|
if entry.get("type") != "STOP":
|
||||||
continue
|
continue
|
||||||
id = entry.get("id", None)
|
|
||||||
|
stop_name = entry.get("name")
|
||||||
|
stop_id = entry.get("id", None)
|
||||||
|
stop_ids[stop_id] = stop_name
|
||||||
|
|
||||||
|
if stop_name == assigned_station:
|
||||||
|
stop_ids.clear()
|
||||||
|
stop_ids[stop_id] = stop_name
|
||||||
break
|
break
|
||||||
|
|
||||||
if id is None:
|
|
||||||
|
if stop_ids is None:
|
||||||
logger(f"Failed to grab ID from '{assigned_station}'", "error")
|
logger(f"Failed to grab ID from '{assigned_station}'", "error")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return id
|
stop_ids_list = list(stop_ids.keys())
|
||||||
|
stops_string = ", ".join(stop_ids.values())
|
||||||
|
logger(f"Availabe stations: {stops_string}")
|
||||||
|
chosen_stop_id = random.choice(stop_ids_list)
|
||||||
|
return chosen_stop_id
|
||||||
|
|
||||||
def get_random_connection(stop_id: str) -> str | None:
|
def get_random_connection(stop_id: str) -> str | None:
|
||||||
if stop_id is None:
|
if stop_id is None:
|
||||||
@@ -100,7 +108,6 @@ def get_random_connection(stop_id: str) -> str | None:
|
|||||||
from_station = entry.get("place", {}).get("name")
|
from_station = entry.get("place", {}).get("name")
|
||||||
break
|
break
|
||||||
|
|
||||||
logger(f"Station: {from_station}")
|
|
||||||
return {
|
return {
|
||||||
"trip_id": trip_id,
|
"trip_id": trip_id,
|
||||||
"from_station": from_station
|
"from_station": from_station
|
||||||
|
|||||||
Reference in New Issue
Block a user