koleo-cli 0.2.137__py3-none-any.whl → 0.2.137.1__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/api.py +2 -2
- koleo/cli.py +13 -12
- koleo/utils.py +20 -0
- {koleo_cli-0.2.137.dist-info → koleo_cli-0.2.137.1.dist-info}/METADATA +1 -1
- koleo_cli-0.2.137.1.dist-info/RECORD +12 -0
- koleo_cli-0.2.137.dist-info/RECORD +0 -12
- {koleo_cli-0.2.137.dist-info → koleo_cli-0.2.137.1.dist-info}/WHEEL +0 -0
- {koleo_cli-0.2.137.dist-info → koleo_cli-0.2.137.1.dist-info}/entry_points.txt +0 -0
- {koleo_cli-0.2.137.dist-info → koleo_cli-0.2.137.1.dist-info}/top_level.txt +0 -0
koleo/api.py
CHANGED
|
@@ -106,11 +106,11 @@ class KoleoAPI:
|
|
|
106
106
|
params = {"brand": brand_name, "nr": number}
|
|
107
107
|
if name:
|
|
108
108
|
params["name"] = name.upper() # WHY!!!!!!!!!
|
|
109
|
-
return self._get_json("/
|
|
109
|
+
return self._get_json("/pl/train_calendars", params=params)
|
|
110
110
|
|
|
111
111
|
def get_train(self, id: int) -> TrainDetailResponse:
|
|
112
112
|
# https://koleo.pl/pl/trains/142821312
|
|
113
|
-
return self._get_json(f"/
|
|
113
|
+
return self._get_json(f"/pl/trains/{id}")
|
|
114
114
|
|
|
115
115
|
def get_connections(
|
|
116
116
|
self,
|
koleo/cli.py
CHANGED
|
@@ -6,7 +6,7 @@ from rich.traceback import install
|
|
|
6
6
|
|
|
7
7
|
from .api import KoleoAPI
|
|
8
8
|
from .types import TrainOnStationInfo, TrainDetailResponse
|
|
9
|
-
from .utils import name_to_slug, parse_datetime, time_dict_to_dt
|
|
9
|
+
from .utils import name_to_slug, parse_datetime, time_dict_to_dt, convert_platform_number
|
|
10
10
|
from .storage import Storage, DEFAULT_CONFIG_PATH
|
|
11
11
|
|
|
12
12
|
install(show_locals=True)
|
|
@@ -87,24 +87,24 @@ class CLI:
|
|
|
87
87
|
|
|
88
88
|
def train_info(self, brand: str, name: str, date: datetime):
|
|
89
89
|
brand = brand.upper().strip()
|
|
90
|
-
name = name.
|
|
91
|
-
cache_id = f"tc-{brand}-{name}"
|
|
90
|
+
name = name.strip()
|
|
92
91
|
if name.isnumeric():
|
|
93
92
|
number = int(name)
|
|
94
|
-
|
|
95
|
-
elif len(parts := name.split(" ")) == 2 or len(parts := name.split("-")) == 2:
|
|
96
|
-
number,
|
|
93
|
+
train_name = ""
|
|
94
|
+
elif len((parts := name.split(" "))) == 2 or len((parts := name.split("-"))) == 2:
|
|
95
|
+
number, train_name = parts
|
|
97
96
|
number = int(number)
|
|
98
97
|
else:
|
|
99
98
|
raise ValueError("Invalid train name!")
|
|
99
|
+
cache_id = f"tc-{brand}-{number}-{name}"
|
|
100
100
|
train_calendars = self.storage.get_cache(cache_id) or self.storage.set_cache(
|
|
101
|
-
cache_id, self.client.get_train_calendars(brand, number,
|
|
101
|
+
cache_id, self.client.get_train_calendars(brand, number, train_name)
|
|
102
102
|
)
|
|
103
103
|
brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
104
104
|
train_id = train_calendars["train_calendars"][0]["date_train_map"][date.strftime("%Y-%m-%d")]
|
|
105
105
|
train_details = self.client.get_train(train_id)
|
|
106
106
|
brand = next(iter(i for i in brands if i["id"] == train_details["train"]["brand_id"]), {}).get("name", "")
|
|
107
|
-
|
|
107
|
+
parts = [f"{brand} {train_details["train"]["train_full_name"]}"]
|
|
108
108
|
vehicle_types: dict[str, str] = {
|
|
109
109
|
stop["station_display_name"]: stop["vehicle_type"]
|
|
110
110
|
for stop in train_details["stops"]
|
|
@@ -115,10 +115,10 @@ class CLI:
|
|
|
115
115
|
start = keys[0]
|
|
116
116
|
for i in range(1, len(keys)):
|
|
117
117
|
if vehicle_types[keys[i]] != vehicle_types[start]:
|
|
118
|
-
|
|
118
|
+
parts.append(f"[bold green] {start} - {keys[i]}:[/bold green] {vehicle_types[start]}")
|
|
119
119
|
start = keys[i]
|
|
120
|
-
|
|
121
|
-
self.console.print(
|
|
120
|
+
parts.append(f"[bold green] {start} - {keys[-1]}:[/bold green] {vehicle_types[start]}")
|
|
121
|
+
self.console.print("\n".join(parts))
|
|
122
122
|
self.console.print(self.train_route_table(train_details))
|
|
123
123
|
|
|
124
124
|
def route(self, start: str, end: str, date: datetime, direct: bool = False, purchasable: bool = False):
|
|
@@ -147,8 +147,9 @@ class CLI:
|
|
|
147
147
|
for stop in train["stops"]:
|
|
148
148
|
arr = time_dict_to_dt(stop["arrival"])
|
|
149
149
|
dep = time_dict_to_dt(stop["departure"])
|
|
150
|
+
platform = convert_platform_number(stop["platform"]) or ""
|
|
150
151
|
parts.append(
|
|
151
|
-
f"[white underline]{stop["distance"] / 1000
|
|
152
|
+
f"[white underline]{stop["distance"] / 1000:^5.1f}km[/white underline] [bold green]{arr.strftime("%H:%M")}[/bold green] - [bold red]{dep.strftime("%H:%M")}[/bold red] [purple]{stop["station_display_name"]} {platform} [/purple]"
|
|
152
153
|
)
|
|
153
154
|
return "\n".join(parts)
|
|
154
155
|
|
koleo/utils.py
CHANGED
|
@@ -39,3 +39,23 @@ TRANSLITERATIONS = {
|
|
|
39
39
|
|
|
40
40
|
def name_to_slug(name: str) -> str:
|
|
41
41
|
return "".join([TRANSLITERATIONS.get(char, char) for char in name.lower()])
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
NUMERAL_TO_ARABIC = {
|
|
45
|
+
"I": 1,
|
|
46
|
+
"II": 2,
|
|
47
|
+
"III": 3,
|
|
48
|
+
"IV": 4,
|
|
49
|
+
"V": 5,
|
|
50
|
+
"VI": 6,
|
|
51
|
+
"VII": 7,
|
|
52
|
+
"VIII": 8,
|
|
53
|
+
"IX": 9,
|
|
54
|
+
"X": 10,
|
|
55
|
+
"XI": 11, # wtf poznań???
|
|
56
|
+
"XII": 12 # just to be safe
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def convert_platform_number(number: str) -> int | None:
|
|
61
|
+
return NUMERAL_TO_ARABIC.get(number)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
koleo/__init__.py,sha256=ChPpKyc4vrcgWj-Uk_ZlDw32s_7iFpE3f1FTAd6zxPY,51
|
|
2
|
+
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
+
koleo/api.py,sha256=uzaOSD_voMRoIxKRuh-RqGKGcJDyAUh3UtOvchW-skc,5052
|
|
4
|
+
koleo/cli.py,sha256=ARSDB6bLYf0c2gSkY_A_b4BoniaMBamCfCUByZsSl5o,9365
|
|
5
|
+
koleo/storage.py,sha256=uCh6edwizAuw1z_Ti5AXvDan2pJAJBSobCVmYw096F8,2015
|
|
6
|
+
koleo/types.py,sha256=8mAsRdNh3jMJwAV5KnHVvDQAekhs0N70EVem4p_w18o,3760
|
|
7
|
+
koleo/utils.py,sha256=vywC_2q_quCdk23GPYXzm6oteCYwHcS3AVwK2pYv1NQ,1224
|
|
8
|
+
koleo_cli-0.2.137.1.dist-info/METADATA,sha256=MXri6goTJkWZs2XgcsdSm-MHie9-53nWXCleo4XVIJU,626
|
|
9
|
+
koleo_cli-0.2.137.1.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
|
10
|
+
koleo_cli-0.2.137.1.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
11
|
+
koleo_cli-0.2.137.1.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
12
|
+
koleo_cli-0.2.137.1.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
koleo/__init__.py,sha256=ChPpKyc4vrcgWj-Uk_ZlDw32s_7iFpE3f1FTAd6zxPY,51
|
|
2
|
-
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
-
koleo/api.py,sha256=8aYn4SsavjOx9cPHLgSlwVmbZaZWJNYpIL3lZPuvdTk,5070
|
|
4
|
-
koleo/cli.py,sha256=fd1O_gO5EF-7BrrLe79j7fn7SEKr5yLgWu33UIjLghM,9230
|
|
5
|
-
koleo/storage.py,sha256=uCh6edwizAuw1z_Ti5AXvDan2pJAJBSobCVmYw096F8,2015
|
|
6
|
-
koleo/types.py,sha256=8mAsRdNh3jMJwAV5KnHVvDQAekhs0N70EVem4p_w18o,3760
|
|
7
|
-
koleo/utils.py,sha256=MYfeQkk9spT2lmlFVsHlpzgnAf0hqN-gKEbgYASqW6U,904
|
|
8
|
-
koleo_cli-0.2.137.dist-info/METADATA,sha256=-PLG8A9e3iD-az9tyrdJEitqThaZrBkOhiWHWuMSPXk,624
|
|
9
|
-
koleo_cli-0.2.137.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
|
10
|
-
koleo_cli-0.2.137.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
11
|
-
koleo_cli-0.2.137.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
12
|
-
koleo_cli-0.2.137.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|