diff --git a/README.md b/README.md index b994e92..84a2af8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config.json.example b/config.json.example index 02675aa..40d0a41 100644 --- a/config.json.example +++ b/config.json.example @@ -13,6 +13,7 @@ "Amsterdam", "Helsinki" ], + "IDs: [] "blacklist": [ "OTHER", "RIDE_SHARING" diff --git a/src/api/transitous.py b/src/api/transitous.py index 37f48ea..6b78aa1 100644 --- a/src/api/transitous.py +++ b/src/api/transitous.py @@ -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) diff --git a/src/config.py b/src/config.py index c08d1c1..cae1cf1 100644 --- a/src/config.py +++ b/src/config.py @@ -14,6 +14,7 @@ class DiscordConfig: @dataclass class ConnectionsConfig: stations: list[str] + IDs: list[str] blacklist: list[str] min_duration: int timezone: str diff --git a/src/data/emojis.py b/src/data/emojis.py index f5f8827..f1f27f2 100644 --- a/src/data/emojis.py +++ b/src/data/emojis.py @@ -7,5 +7,6 @@ emoji_list = { "HIGHSPEED_RAIL": "🚅", "LONG_DISTANCE": "🚅", "METRO": "🚇", - "SUBWAY": "🚇" + "SUBWAY": "🚇", + "FERRY": "🚢" } \ No newline at end of file diff --git a/src/data/operators.py b/src/data/operators.py index df87c8f..33c8d10 100644 --- a/src/data/operators.py +++ b/src/data/operators.py @@ -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 } } diff --git a/src/dc/handlers.py b/src/dc/handlers.py index 6e9febd..8bc41c3 100644 --- a/src/dc/handlers.py +++ b/src/dc/handlers.py @@ -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")