koleo-cli 0.2.137.8__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 CHANGED
@@ -6,7 +6,7 @@ from rich.console import Console
6
6
 
7
7
  from .api import KoleoAPI
8
8
  from .storage import DEFAULT_CONFIG_PATH, Storage
9
- from .types import ExtendedBaseStationInfo, TrainDetailResponse, TrainOnStationInfo
9
+ from .types import ExtendedBaseStationInfo, TrainDetailResponse, TrainOnStationInfo, TrainCalendar
10
10
  from .utils import RemainderString, arr_dep_to_dt, convert_platform_number, name_to_slug, parse_datetime
11
11
 
12
12
 
@@ -101,7 +101,7 @@ class CLI:
101
101
  f"[bold blue][link=https://koleo.pl/dworzec-pkp/{st["name_slug"]}]{st["name"]}[/bold blue] ID: {st["id"]}[/link]"
102
102
  )
103
103
 
104
- def train_info(self, brand: str, name: str, date: datetime):
104
+ def get_train_calendars(self, brand: str, name: str) -> list[TrainCalendar]:
105
105
  brand = brand.upper().strip()
106
106
  name_parts = name.split(" ")
107
107
  if len(name_parts) == 1 and name_parts[0].isnumeric():
@@ -126,21 +126,47 @@ class CLI:
126
126
  except self.client.errors.KoleoNotFound:
127
127
  self.print(f'[bold red]Train not found: nr={number}, name="{train_name}"[/bold red]')
128
128
  exit(2)
129
- train_id = train_calendars["train_calendars"][0]["date_train_map"][date.strftime("%Y-%m-%d")]
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):
130
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())
131
151
  brand = next(iter(i for i in brands if i["id"] == train_details["train"]["brand_id"]), {}).get("logo_text", "")
152
+
132
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
+
133
156
  route_start = arr_dep_to_dt(train_details["stops"][0]["departure"])
134
157
  route_end = arr_dep_to_dt(train_details["stops"][-1]["arrival"])
158
+
135
159
  if route_end.hour < route_start.hour or (
136
160
  route_end.hour == route_start.hour and route_end.minute < route_end.minute
137
161
  ):
138
162
  route_end += timedelta(days=1)
163
+
139
164
  travel_time = route_end - route_start
140
165
  speed = train_details["stops"][-1]["distance"] / 1000 / travel_time.seconds * 3600
141
166
  parts.append(
142
167
  f"[white] {travel_time.seconds//3600}h{(travel_time.seconds % 3600)/60:.0f}m {speed:^4.1f}km/h [/white]"
143
168
  )
169
+
144
170
  vehicle_types: dict[str, str] = {
145
171
  stop["station_display_name"]: stop["vehicle_type"]
146
172
  for stop in train_details["stops"]
@@ -333,7 +359,7 @@ def main():
333
359
  train_route = subparsers.add_parser(
334
360
  "trainroute",
335
361
  aliases=["r", "tr", "t", "poc", "pociąg"],
336
- help="Allows you to show the train's route",
362
+ help="Allows you to check the train's route",
337
363
  )
338
364
  train_route.add_argument("brand", help="The brand name", type=str)
339
365
  train_route.add_argument("name", help="The train name", nargs="+", action=RemainderString)
@@ -346,6 +372,23 @@ def main():
346
372
  )
347
373
  train_route.set_defaults(func=cli.train_info, pass_=["brand", "name", "date"])
348
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
+
349
392
  stations = subparsers.add_parser(
350
393
  "stations", aliases=["s", "find", "f", "stacje", "ls", "q"], help="Allows you to find stations by their name"
351
394
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: koleo-cli
3
- Version: 0.2.137.8
3
+ Version: 0.2.137.9
4
4
  Summary: Koleo CLI
5
5
  Home-page: https://github.com/lzgirlcat/koleo-cli
6
6
  Author: Zoey !
@@ -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=WJARHIDzhjQuKxlsjjkNkGbnOprU_I-KfL3ZI383EyI,18533
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.8.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
9
- koleo_cli-0.2.137.8.dist-info/METADATA,sha256=2_4tYhSb6u865m96qR6CbwJtWPFep8LJlTioym5Eo60,3095
10
- koleo_cli-0.2.137.8.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
11
- koleo_cli-0.2.137.8.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
12
- koleo_cli-0.2.137.8.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
13
- koleo_cli-0.2.137.8.dist-info/RECORD,,
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,,