koleo-cli 0.2.137.7__tar.gz → 0.2.137.9__tar.gz

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: koleo-cli
3
- Version: 0.2.137.7
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 !
@@ -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 train_info(self, brand: str, name: str, date: datetime):
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
- 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):
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 show the train's route",
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: koleo-cli
3
- Version: 0.2.137.7
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 !
@@ -14,7 +14,7 @@ def parse_requirements_file(path):
14
14
 
15
15
  setuptools.setup(
16
16
  name="koleo-cli",
17
- version="0.2.137.7",
17
+ version="0.2.137.9",
18
18
  description="Koleo CLI",
19
19
  long_description=long_description(),
20
20
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes