koleo-cli 0.2.137.7__py3-none-any.whl → 0.2.137.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of koleo-cli might be problematic. Click here for more details.
- koleo/cli.py +47 -8
- {koleo_cli-0.2.137.7.dist-info → koleo_cli-0.2.137.9.dist-info}/METADATA +1 -1
- {koleo_cli-0.2.137.7.dist-info → koleo_cli-0.2.137.9.dist-info}/RECORD +7 -7
- {koleo_cli-0.2.137.7.dist-info → koleo_cli-0.2.137.9.dist-info}/LICENSE +0 -0
- {koleo_cli-0.2.137.7.dist-info → koleo_cli-0.2.137.9.dist-info}/WHEEL +0 -0
- {koleo_cli-0.2.137.7.dist-info → koleo_cli-0.2.137.9.dist-info}/entry_points.txt +0 -0
- {koleo_cli-0.2.137.7.dist-info → koleo_cli-0.2.137.9.dist-info}/top_level.txt +0 -0
koleo/cli.py
CHANGED
|
@@ -3,17 +3,13 @@ from argparse import ArgumentParser
|
|
|
3
3
|
from datetime import datetime, timedelta
|
|
4
4
|
|
|
5
5
|
from rich.console import Console
|
|
6
|
-
from rich.traceback import install
|
|
7
6
|
|
|
8
7
|
from .api import KoleoAPI
|
|
9
8
|
from .storage import DEFAULT_CONFIG_PATH, Storage
|
|
10
|
-
from .types import ExtendedBaseStationInfo, TrainDetailResponse, TrainOnStationInfo
|
|
9
|
+
from .types import ExtendedBaseStationInfo, TrainDetailResponse, TrainOnStationInfo, TrainCalendar
|
|
11
10
|
from .utils import RemainderString, arr_dep_to_dt, convert_platform_number, name_to_slug, parse_datetime
|
|
12
11
|
|
|
13
12
|
|
|
14
|
-
install(show_locals=True, max_frames=2)
|
|
15
|
-
|
|
16
|
-
|
|
17
13
|
class CLI:
|
|
18
14
|
def __init__(
|
|
19
15
|
self,
|
|
@@ -105,7 +101,7 @@ class CLI:
|
|
|
105
101
|
f"[bold blue][link=https://koleo.pl/dworzec-pkp/{st["name_slug"]}]{st["name"]}[/bold blue] ID: {st["id"]}[/link]"
|
|
106
102
|
)
|
|
107
103
|
|
|
108
|
-
def
|
|
104
|
+
def get_train_calendars(self, brand: str, name: str) -> list[TrainCalendar]:
|
|
109
105
|
brand = brand.upper().strip()
|
|
110
106
|
name_parts = name.split(" ")
|
|
111
107
|
if len(name_parts) == 1 and name_parts[0].isnumeric():
|
|
@@ -130,21 +126,47 @@ class CLI:
|
|
|
130
126
|
except self.client.errors.KoleoNotFound:
|
|
131
127
|
self.print(f'[bold red]Train not found: nr={number}, name="{train_name}"[/bold red]')
|
|
132
128
|
exit(2)
|
|
133
|
-
|
|
129
|
+
return train_calendars["train_calendars"]
|
|
130
|
+
|
|
131
|
+
def train_calendar(self, brand: str, name: str):
|
|
132
|
+
train_calendars = self.get_train_calendars(brand, name)
|
|
133
|
+
brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
134
|
+
for calendar in train_calendars:
|
|
135
|
+
brand = next(iter(i for i in brands if i["id"] == calendar["trainBrand"]), {}).get("logo_text", "")
|
|
136
|
+
parts = [f"[red]{brand}[/red] [bold blue]{calendar['train_nr']}{" "+ v if (v:=calendar.get("train_name")) else ""}[/bold blue]:"]
|
|
137
|
+
for k, v in calendar["date_train_map"].items():
|
|
138
|
+
parts.append(f" [bold green]{k}[/bold green]: [purple]{v}[/purple]")
|
|
139
|
+
self.print("\n".join(parts))
|
|
140
|
+
|
|
141
|
+
def train_info(self, brand: str, name: str, date: datetime):
|
|
142
|
+
train_calendars = self.get_train_calendars(brand, name)
|
|
143
|
+
if not (train_id:=train_calendars[0]["date_train_map"].get(date.strftime("%Y-%m-%d"))):
|
|
144
|
+
self.print(f"[bold red]This train doesn't run on the selected date: {date.strftime("%Y-%m-%d")}[/bold red]")
|
|
145
|
+
exit(2)
|
|
146
|
+
self.train_detail(train_id)
|
|
147
|
+
|
|
148
|
+
def train_detail(self, train_id: int):
|
|
134
149
|
train_details = self.client.get_train(train_id)
|
|
150
|
+
brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
135
151
|
brand = next(iter(i for i in brands if i["id"] == train_details["train"]["brand_id"]), {}).get("logo_text", "")
|
|
152
|
+
|
|
136
153
|
parts = [f"[red]{brand}[/red] [bold blue]{train_details["train"]["train_full_name"]}[/bold blue]"]
|
|
154
|
+
parts.append(f" {train_details["train"]["run_desc"]}")
|
|
155
|
+
|
|
137
156
|
route_start = arr_dep_to_dt(train_details["stops"][0]["departure"])
|
|
138
157
|
route_end = arr_dep_to_dt(train_details["stops"][-1]["arrival"])
|
|
158
|
+
|
|
139
159
|
if route_end.hour < route_start.hour or (
|
|
140
160
|
route_end.hour == route_start.hour and route_end.minute < route_end.minute
|
|
141
161
|
):
|
|
142
162
|
route_end += timedelta(days=1)
|
|
163
|
+
|
|
143
164
|
travel_time = route_end - route_start
|
|
144
165
|
speed = train_details["stops"][-1]["distance"] / 1000 / travel_time.seconds * 3600
|
|
145
166
|
parts.append(
|
|
146
167
|
f"[white] {travel_time.seconds//3600}h{(travel_time.seconds % 3600)/60:.0f}m {speed:^4.1f}km/h [/white]"
|
|
147
168
|
)
|
|
169
|
+
|
|
148
170
|
vehicle_types: dict[str, str] = {
|
|
149
171
|
stop["station_display_name"]: stop["vehicle_type"]
|
|
150
172
|
for stop in train_details["stops"]
|
|
@@ -337,7 +359,7 @@ def main():
|
|
|
337
359
|
train_route = subparsers.add_parser(
|
|
338
360
|
"trainroute",
|
|
339
361
|
aliases=["r", "tr", "t", "poc", "pociąg"],
|
|
340
|
-
help="Allows you to
|
|
362
|
+
help="Allows you to check the train's route",
|
|
341
363
|
)
|
|
342
364
|
train_route.add_argument("brand", help="The brand name", type=str)
|
|
343
365
|
train_route.add_argument("name", help="The train name", nargs="+", action=RemainderString)
|
|
@@ -350,6 +372,23 @@ def main():
|
|
|
350
372
|
)
|
|
351
373
|
train_route.set_defaults(func=cli.train_info, pass_=["brand", "name", "date"])
|
|
352
374
|
|
|
375
|
+
train_calendar = subparsers.add_parser(
|
|
376
|
+
"traincalendar",
|
|
377
|
+
aliases=["kursowanie", "tc", "k"],
|
|
378
|
+
help="Allows you to check what days the train runs on",
|
|
379
|
+
)
|
|
380
|
+
train_calendar.add_argument("brand", help="The brand name", type=str)
|
|
381
|
+
train_calendar.add_argument("name", help="The train name", nargs="+", action=RemainderString)
|
|
382
|
+
train_calendar.set_defaults(func=cli.train_calendar, pass_=["brand", "name"])
|
|
383
|
+
|
|
384
|
+
train_detail = subparsers.add_parser(
|
|
385
|
+
"traindetail",
|
|
386
|
+
aliases=["td", "tid", "id", "idpoc"],
|
|
387
|
+
help="Allows you to show the train's route given it's koleo ID",
|
|
388
|
+
)
|
|
389
|
+
train_detail.add_argument("train_id", help="The koleo ID", type=int)
|
|
390
|
+
train_detail.set_defaults(func=cli.train_detail, pass_=["train_id"])
|
|
391
|
+
|
|
353
392
|
stations = subparsers.add_parser(
|
|
354
393
|
"stations", aliases=["s", "find", "f", "stacje", "ls", "q"], help="Allows you to find stations by their name"
|
|
355
394
|
)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
koleo/__init__.py,sha256=N_IkOBZCSPCCw31Hu72CFys707PziGFmXpNVl0CXAz8,47
|
|
2
2
|
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
3
|
koleo/api.py,sha256=07PSwLFmirdJ_JhPBJ7rO1nv_v90njIcwmOoxT4P_4M,5708
|
|
4
|
-
koleo/cli.py,sha256=
|
|
4
|
+
koleo/cli.py,sha256=_ahP1RWnlCtoM857fKZgbdO_eQQiuyDEdhYA2RoX784,20627
|
|
5
5
|
koleo/storage.py,sha256=_VztM8d3YTnmZOR9JvOsobThrQhb4gEzT1azC8N7baY,2024
|
|
6
6
|
koleo/types.py,sha256=pjVCIH39rUNeipazeRKOuTRCWoslLdbGivKiQmfd5Pw,5226
|
|
7
7
|
koleo/utils.py,sha256=CsYWNf3IPhHJln445tzXSA7r2z3NpmqVSmw8Rrb7YT0,1822
|
|
8
|
-
koleo_cli-0.2.137.
|
|
9
|
-
koleo_cli-0.2.137.
|
|
10
|
-
koleo_cli-0.2.137.
|
|
11
|
-
koleo_cli-0.2.137.
|
|
12
|
-
koleo_cli-0.2.137.
|
|
13
|
-
koleo_cli-0.2.137.
|
|
8
|
+
koleo_cli-0.2.137.9.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
9
|
+
koleo_cli-0.2.137.9.dist-info/METADATA,sha256=xfSWLLtbGywsL7CqQ9buD9bKWE1okzZyvo3kyWqyj2Q,3095
|
|
10
|
+
koleo_cli-0.2.137.9.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
11
|
+
koleo_cli-0.2.137.9.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
12
|
+
koleo_cli-0.2.137.9.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
13
|
+
koleo_cli-0.2.137.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|