transitous rewrite: add IDs

This commit is contained in:
Kaaninchen
2026-08-18 14:14:10 +02:00
parent a6342ca039
commit 729f350924
7 changed files with 39 additions and 7 deletions
+6
View File
@@ -53,6 +53,7 @@ I added an [example config](config.json.example):
"Amsterdam",
"Helsinki"
],
"IDs": [],
"blacklist": [
"OTHER",
"RIDE_SHARING"
@@ -164,6 +165,11 @@ The tool will also ask if it should save a .json file with more informations for
If you choose to generate the json, then you'll find the file as `stations.json` in the same directory as `main.py`
##### IDs
For every station inside of the `stations.json` you'll find an ID. You can add that ID to `"IDs"` to really specify that you would like to use THAT station, and not a different one.
This is especially useful if you want to add a station whose name isn't unique and also used by other stations. The bot would falsely use the first station with the same name and consider it an exact match, even if you wanted a different one. This won't happen with the ID, as every ID is uniquely assigned to only one station.
##### blacklist
You can blacklist specific types of transport, the bot would then skip them while selecting a connection. You can get the type either in your console (mode)
```sh
+1
View File
@@ -13,6 +13,7 @@
"Amsterdam",
"Helsinki"
],
"IDs: []
"blacklist": [
"OTHER",
"RIDE_SHARING"
+24 -4
View File
@@ -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)
+1
View File
@@ -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
View File
@@ -7,5 +7,6 @@ emoji_list = {
"HIGHSPEED_RAIL": "🚅",
"LONG_DISTANCE": "🚅",
"METRO": "🚇",
"SUBWAY": "🚇"
"SUBWAY": "🚇",
"FERRY": "🚢"
}
+4
View File
@@ -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
View File
@@ -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")