mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: add IDs
This commit is contained in:
+24
-4
@@ -8,7 +8,8 @@ from src.config import config
|
||||
from src.lang.locales import lang
|
||||
|
||||
|
||||
stations = config.connections.stations
|
||||
station_names = config.connections.stations
|
||||
station_IDs = config.connections.IDs
|
||||
blacklist = config.connections.blacklist
|
||||
long_name_lang = lang.channel.long_name
|
||||
user_agent = config.http.user_agent
|
||||
@@ -25,7 +26,7 @@ def check_stations():
|
||||
"stations": {}
|
||||
}
|
||||
|
||||
for station in stations:
|
||||
for station in station_names:
|
||||
req = f"{endpoint}/api/v1/geocode"
|
||||
|
||||
try:
|
||||
@@ -91,7 +92,26 @@ def check_stations():
|
||||
|
||||
|
||||
def get_random_stop_id() -> str | None:
|
||||
assigned_station = random.choice(stations)
|
||||
stations = {}
|
||||
|
||||
if len(station_names) > 0:
|
||||
for entry in station_names:
|
||||
if entry != "":
|
||||
stations[entry] = "name"
|
||||
|
||||
if len(station_IDs) > 0:
|
||||
for entry in station_IDs:
|
||||
if entry != "":
|
||||
stations[entry] = "ID"
|
||||
|
||||
if not stations:
|
||||
logger("Both stations and IDs are empty...", "FATAL")
|
||||
|
||||
assigned_station = random.choice(list(stations.keys()))
|
||||
|
||||
if stations[assigned_station] == "ID":
|
||||
return assigned_station
|
||||
|
||||
req = f"{endpoint}/api/v1/geocode"
|
||||
|
||||
try:
|
||||
@@ -175,7 +195,7 @@ def get_random_connection(stop_id: str) -> str | None:
|
||||
break
|
||||
|
||||
if not trip_ids:
|
||||
logger("Couldn't find any connection", "error")
|
||||
logger("Couldn't find any connections", "error")
|
||||
return None
|
||||
trip_id = random.choice(trip_ids)
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class DiscordConfig:
|
||||
@dataclass
|
||||
class ConnectionsConfig:
|
||||
stations: list[str]
|
||||
IDs: list[str]
|
||||
blacklist: list[str]
|
||||
min_duration: int
|
||||
timezone: str
|
||||
|
||||
+2
-1
@@ -7,5 +7,6 @@ emoji_list = {
|
||||
"HIGHSPEED_RAIL": "🚅",
|
||||
"LONG_DISTANCE": "🚅",
|
||||
"METRO": "🚇",
|
||||
"SUBWAY": "🚇"
|
||||
"SUBWAY": "🚇",
|
||||
"FERRY": "🚢"
|
||||
}
|
||||
@@ -101,6 +101,10 @@ OPERATORS = {
|
||||
"Flixbus": {
|
||||
"logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9e/Flixbus_201x_logo.svg/1280px-Flixbus_201x_logo.svg.png",
|
||||
"color": 0x8CD541
|
||||
},
|
||||
"Tallink Grupp AS": {
|
||||
"logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9e/Tallink_logo.svg/330px-Tallink_logo.svg.png",
|
||||
"color": 0x225197
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -130,7 +130,7 @@ async def _update_next_loop(bot: discord.Bot, voice_channel: discord.VoiceChanne
|
||||
'''
|
||||
now = datetime.now(LOCAL_TZ)
|
||||
departure_dt = trip["departure_dt"]
|
||||
|
||||
|
||||
if departure_dt > now:
|
||||
wait_seconds = (departure_dt - now).total_seconds()
|
||||
await asyncio.sleep(wait_seconds)
|
||||
@@ -143,7 +143,6 @@ async def _update_next_loop(bot: discord.Bot, voice_channel: discord.VoiceChanne
|
||||
return
|
||||
|
||||
next_stop_str = next_stop["name"]
|
||||
print(next_stop_str)
|
||||
|
||||
status_text = f"{lang.embeds.info.next_stop()}: {next_stop_str}"
|
||||
await voice_channel.set_status(status_text, reason="Next stop status")
|
||||
|
||||
Reference in New Issue
Block a user