koleo-cli 0.2.137.20__py3-none-any.whl → 0.2.137.22__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/base.py CHANGED
@@ -104,3 +104,17 @@ class BaseCli:
104
104
  async def get_station_by_id(self, id: int):
105
105
  key = f"st-{id}"
106
106
  return self.storage.get_cache(key) or self.storage.set_cache(key, await self.client.get_station_by_id(id))
107
+
108
+ async def get_brand_by_shortcut(self, s: str, *, name: str | None = None):
109
+ brands = await self.get_brands()
110
+ s = s.upper()
111
+ if name and "SŁONECZNY" in name and s == "KM":
112
+ return "SLONECZNY" # OH MY FUCKING GOD
113
+ if s == "AR":
114
+ return "ARRIVARP"
115
+ if s not in [i["name"] for i in brands]:
116
+ res = {i["logo_text"]: i["name"] for i in brands}.get(s)
117
+ if not res:
118
+ await self.error_and_exit(f"Invalid brand name not found: [underline]{s},[/underline]")
119
+ return res
120
+ return s
koleo/cli/train_info.py CHANGED
@@ -8,7 +8,7 @@ from koleo.utils import koleo_time_to_dt
8
8
 
9
9
  class TrainInfo(BaseCli):
10
10
  async def get_train_calendars(self, brand: str, name: str) -> list[TrainCalendar]:
11
- brand = brand.upper().strip()
11
+ brand = await self.get_brand_by_shortcut(brand, name=name)
12
12
  name_parts = name.split(" ")
13
13
  if len(name_parts) == 1 and name_parts[0].isnumeric():
14
14
  number = int(name_parts[0])
@@ -18,12 +18,7 @@ class TrainInfo(BaseCli):
18
18
  train_name = " ".join(name_parts)
19
19
  else:
20
20
  raise ValueError("Invalid train name!")
21
- brands = await self.get_brands()
22
- if brand not in [i["name"] for i in brands]:
23
- res = {i["logo_text"]: i["name"] for i in brands}.get(brand)
24
- if not res:
25
- raise ValueError("Invalid brand name!")
26
- brand = res
21
+
27
22
  cache_id = f"tc-{brand}-{number}-{name}"
28
23
  try:
29
24
  train_calendars = self.storage.get_cache(cache_id) or self.storage.set_cache(
@@ -38,7 +33,7 @@ class TrainInfo(BaseCli):
38
33
  brands = await self.get_brands()
39
34
  for calendar in train_calendars:
40
35
  brand_obj = next(iter(i for i in brands if i["id"] == calendar["trainBrand"]), {})
41
- link = f"https://koleo.pl/pociag/{brand_obj["name"]}/{name.replace(" ", "-")}"
36
+ link = f"https://koleo.pl/pociag/{brand_obj["name"]}/{name.replace(" ", "-", 1).replace(" ", "%20")}"
42
37
  brand = brand_obj.get("logo_text", "")
43
38
  self.print(
44
39
  f"[red][link={link}]{brand}[/red] [bold blue]{calendar['train_nr']}{" "+ v if (v:=calendar.get("train_name")) else ""}[/bold blue]:[/link]"
@@ -98,9 +93,10 @@ class TrainInfo(BaseCli):
98
93
  brands = await self.get_brands()
99
94
  brand_obj = next(iter(i for i in brands if i["id"] == train_details["train"]["brand_id"]), {})
100
95
  brand = brand_obj.get("logo_text", "")
96
+ url_brand = await self.get_brand_by_shortcut(brand, name=train_details["train"]["train_full_name"])
101
97
 
102
98
  link = (
103
- f"https://koleo.pl/pociag/{brand_obj["name"]}/{train_details["train"]["train_full_name"].replace(" ", "-")}"
99
+ f"https://koleo.pl/pociag/{url_brand}/{train_details["train"]["train_full_name"].replace(" ", "-", 1).replace(" ", "%20")}"
104
100
  )
105
101
  if date:
106
102
  link += f"/{date}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koleo-cli
3
- Version: 0.2.137.20
3
+ Version: 0.2.137.22
4
4
  Summary: Koleo CLI
5
5
  Home-page: https://github.com/lzgirlcat/koleo-cli
6
6
  Author: Zoey !
@@ -11,16 +11,16 @@ koleo/api/logging.py,sha256=VhOFY6N_mofFfg9ZJ5ZnDVCzNuRilqLqrzZU9b-hpZY,1644
11
11
  koleo/api/types.py,sha256=udCQeDjRvUqrUkuE_-Jidzsq_FOCjNyGd_bQWm3f9iA,10594
12
12
  koleo/cli/__init__.py,sha256=50B_lMtZS27_FVrkIa2TOWMX7SozG1CPPMxbY1W9tqk,266
13
13
  koleo/cli/aliases.py,sha256=is3NX5g0-ujJTmyjlFLoNnK_pwoYUVIojWNkgwXRBKk,581
14
- koleo/cli/base.py,sha256=HOEve9aNsL_CcqaKjDFwt1mVDG6J15kY01DpWDV-jL4,4366
14
+ koleo/cli/base.py,sha256=4vnQ4HS5GD6WXReWiJs1E7Bt8cDU4anlZCDb8xXqXS0,4954
15
15
  koleo/cli/connections.py,sha256=LJzoq3ADVUmBeqF4-h_me3pZbBHYg1sG3MaDYprwuLU,6873
16
16
  koleo/cli/seats.py,sha256=h7pRWdeQ8frHD1ZuiGZO6UGQRboty9PtiVHg49lkw4Q,6337
17
17
  koleo/cli/station_board.py,sha256=lRGIeEKEOvUcctM6cwmqVE7Yk9m9R12gfFZahlWLQFc,3669
18
18
  koleo/cli/stations.py,sha256=6L3PBWc6xssyR9eeLacuvGBJmaY7Ny3DalKy2Xq7zsA,1633
19
- koleo/cli/train_info.py,sha256=XS_G4dsevHBPuGSpsbNTh_adSLyedame7WVe71oIe5M,7259
19
+ koleo/cli/train_info.py,sha256=wWsbbvpNmm54_0FBvr_TEhhplhD8byKKYs_VvfpvOcs,7164
20
20
  koleo/cli/utils.py,sha256=FzPGcJdwRwcz10mYiW63Y4zpjM9j6DzNH91UNR3MS8s,666
21
- koleo_cli-0.2.137.20.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
22
- koleo_cli-0.2.137.20.dist-info/METADATA,sha256=kLBn-foH2sAXe1fBqDG3TsTu10ZjbgS1QlKiV99zKG4,4731
23
- koleo_cli-0.2.137.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
- koleo_cli-0.2.137.20.dist-info/entry_points.txt,sha256=ouWbMR_XWpEwV7zfkFKeiFLe_IMP-47kTvVahgy4PRg,42
25
- koleo_cli-0.2.137.20.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
26
- koleo_cli-0.2.137.20.dist-info/RECORD,,
21
+ koleo_cli-0.2.137.22.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
22
+ koleo_cli-0.2.137.22.dist-info/METADATA,sha256=QQehYoUOPqA7BiVk7szVD7ZtBZ7vKqoWF0ClMndHITU,4731
23
+ koleo_cli-0.2.137.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ koleo_cli-0.2.137.22.dist-info/entry_points.txt,sha256=ouWbMR_XWpEwV7zfkFKeiFLe_IMP-47kTvVahgy4PRg,42
25
+ koleo_cli-0.2.137.22.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
26
+ koleo_cli-0.2.137.22.dist-info/RECORD,,