koleo-cli 0.2.137.2__py3-none-any.whl → 0.2.137.3__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 +1 -1
- koleo/cli.py +43 -12
- {koleo_cli-0.2.137.2.dist-info → koleo_cli-0.2.137.3.dist-info}/METADATA +1 -1
- koleo_cli-0.2.137.3.dist-info/RECORD +12 -0
- koleo_cli-0.2.137.2.dist-info/RECORD +0 -12
- {koleo_cli-0.2.137.2.dist-info → koleo_cli-0.2.137.3.dist-info}/WHEEL +0 -0
- {koleo_cli-0.2.137.2.dist-info → koleo_cli-0.2.137.3.dist-info}/entry_points.txt +0 -0
- {koleo_cli-0.2.137.2.dist-info → koleo_cli-0.2.137.3.dist-info}/top_level.txt +0 -0
koleo/api.py
CHANGED
|
@@ -86,7 +86,7 @@ class KoleoAPI:
|
|
|
86
86
|
|
|
87
87
|
def find_station(self, query: str, language: str = "pl") -> list[ExtendedStationInfo]:
|
|
88
88
|
# https://koleo.pl/ls?q=tere&language=pl
|
|
89
|
-
return self._get_json("/ls",
|
|
89
|
+
return self._get_json("/ls", params={"q": query, "language": language})["stations"]
|
|
90
90
|
|
|
91
91
|
def get_station_by_slug(self, slug: str) -> ExtendedBaseStationInfo:
|
|
92
92
|
# https://koleo.pl/api/v2/main/stations/by_slug/inowroclaw
|
koleo/cli.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import re
|
|
1
2
|
from argparse import ArgumentParser
|
|
2
3
|
from datetime import datetime, timedelta
|
|
3
4
|
|
|
@@ -22,7 +23,16 @@ class CLI:
|
|
|
22
23
|
) -> None:
|
|
23
24
|
self._client = client
|
|
24
25
|
self._storage = storage
|
|
25
|
-
self.
|
|
26
|
+
self.no_color = no_color
|
|
27
|
+
self.console = Console(color_system="standard", no_color=no_color, highlight=False)
|
|
28
|
+
|
|
29
|
+
def print(self, text, *args, **kwargs):
|
|
30
|
+
if self.no_color:
|
|
31
|
+
result = re.sub(r'\[[^\]]*\]', '', text)
|
|
32
|
+
print(result)
|
|
33
|
+
else:
|
|
34
|
+
self.console.print(text, *args, **kwargs)
|
|
35
|
+
|
|
26
36
|
|
|
27
37
|
@property
|
|
28
38
|
def client(self) -> KoleoAPI:
|
|
@@ -59,7 +69,7 @@ class CLI:
|
|
|
59
69
|
if datetime.fromisoformat(i["departure"]).timestamp() > date.timestamp() # type: ignore
|
|
60
70
|
]
|
|
61
71
|
table = self.trains_on_station_table(trains)
|
|
62
|
-
self.
|
|
72
|
+
self.print(table)
|
|
63
73
|
return table
|
|
64
74
|
|
|
65
75
|
def get_arrivals(self, station_id: int, date: datetime):
|
|
@@ -74,21 +84,32 @@ class CLI:
|
|
|
74
84
|
if datetime.fromisoformat(i["arrival"]).timestamp() > date.timestamp() # type: ignore
|
|
75
85
|
]
|
|
76
86
|
table = self.trains_on_station_table(trains, type=2)
|
|
77
|
-
self.
|
|
87
|
+
self.print(table)
|
|
78
88
|
return table
|
|
79
89
|
|
|
80
90
|
def full_departures(self, station: str, date: datetime):
|
|
81
91
|
st = self.get_station(station)
|
|
82
92
|
station_info = f"[bold blue]{st["name"]}[/bold blue] ID: {st["id"]}"
|
|
83
|
-
self.
|
|
93
|
+
self.print(station_info)
|
|
84
94
|
self.get_departures(st["id"], date)
|
|
85
95
|
|
|
86
96
|
def full_arrivals(self, station: str, date: datetime):
|
|
87
97
|
st = self.get_station(station)
|
|
88
98
|
station_info = f"[bold blue]{st["name"]}[/bold blue] ID: {st["id"]}"
|
|
89
|
-
self.
|
|
99
|
+
self.print(station_info)
|
|
90
100
|
self.get_arrivals(st["id"], date)
|
|
91
101
|
|
|
102
|
+
def find_station(self, query: str | None):
|
|
103
|
+
if query:
|
|
104
|
+
stations = self.client.find_station(query)
|
|
105
|
+
else:
|
|
106
|
+
stations = (
|
|
107
|
+
self.storage.get_cache("stations") or
|
|
108
|
+
self.storage.set_cache("stations", self.client.get_stations())
|
|
109
|
+
)
|
|
110
|
+
for st in stations:
|
|
111
|
+
self.print(f"[bold blue]{st["name"]}[/bold blue] ID: {st["id"]}")
|
|
112
|
+
|
|
92
113
|
def train_info(self, brand: str, name: str, date: datetime):
|
|
93
114
|
brand = brand.upper().strip()
|
|
94
115
|
name = name.strip()
|
|
@@ -113,7 +134,7 @@ class CLI:
|
|
|
113
134
|
train_id = train_calendars["train_calendars"][0]["date_train_map"][date.strftime("%Y-%m-%d")]
|
|
114
135
|
train_details = self.client.get_train(train_id)
|
|
115
136
|
brand = next(iter(i for i in brands if i["id"] == train_details["train"]["brand_id"]), {}).get("logo_text", "")
|
|
116
|
-
parts = [f"{brand} {train_details["train"]["train_full_name"]}"]
|
|
137
|
+
parts = [f"[red]{brand}[/red] [bold blue]{train_details["train"]["train_full_name"]}[/bold blue]"]
|
|
117
138
|
route_start = arr_dep_to_dt(train_details["stops"][0]["departure"])
|
|
118
139
|
route_end = arr_dep_to_dt(train_details["stops"][-1]["arrival"])
|
|
119
140
|
if route_end.hour < route_start.hour or (route_end.hour==route_start.hour and route_end.minute < route_end.minute):
|
|
@@ -134,8 +155,8 @@ class CLI:
|
|
|
134
155
|
parts.append(f"[bold green] {start} - {keys[i]}:[/bold green] {vehicle_types[start]}")
|
|
135
156
|
start = keys[i]
|
|
136
157
|
parts.append(f"[bold green] {start} - {keys[-1]}:[/bold green] {vehicle_types[start]}")
|
|
137
|
-
self.
|
|
138
|
-
self.
|
|
158
|
+
self.print("\n".join(parts))
|
|
159
|
+
self.print(self.train_route_table(train_details))
|
|
139
160
|
|
|
140
161
|
def connections(self, start: str, end: str, date: datetime, brands: list[str], direct: bool = False, purchasable: bool = False):
|
|
141
162
|
start_station = self.get_station(start)
|
|
@@ -147,7 +168,7 @@ class CLI:
|
|
|
147
168
|
else:
|
|
148
169
|
connection_brands = [i["id"] for i in api_brands if i["name"].lower().strip() in brands or i["logo_text"].lower().strip() in brands]
|
|
149
170
|
if not connection_brands:
|
|
150
|
-
self.
|
|
171
|
+
self.print(f'[bold red]No brands match: "{', '.join(brands)}"[/bold red]')
|
|
151
172
|
exit(2)
|
|
152
173
|
connections = self.client.get_connections(
|
|
153
174
|
start_station["name_slug"],
|
|
@@ -168,7 +189,7 @@ class CLI:
|
|
|
168
189
|
platform = convert_platform_number(train["platform"]) if train["platform"] else ""
|
|
169
190
|
position_info = f"{platform}/{train["track"]}" if train["track"] else platform
|
|
170
191
|
parts.append(
|
|
171
|
-
f"[bold green]{time[11:16]}[/bold green] {brand} {train["train_full_name"]}[purple] {train["stations"][0]["name"]} {position_info}[/purple]"
|
|
192
|
+
f"[bold green]{time[11:16]}[/bold green] [red]{brand}[/red] {train["train_full_name"]}[purple] {train["stations"][0]["name"]} {position_info}[/purple]"
|
|
172
193
|
)
|
|
173
194
|
return "\n".join(parts)
|
|
174
195
|
|
|
@@ -190,7 +211,7 @@ class CLI:
|
|
|
190
211
|
f"st-{slug}", self.client.get_station_by_slug(slug)
|
|
191
212
|
)
|
|
192
213
|
except self.client.errors.KoleoNotFound:
|
|
193
|
-
self.
|
|
214
|
+
self.print(f'[bold red]Station not found: "{station}"[/bold red]')
|
|
194
215
|
exit(2)
|
|
195
216
|
|
|
196
217
|
def main():
|
|
@@ -251,9 +272,18 @@ def main():
|
|
|
251
272
|
)
|
|
252
273
|
train_route.set_defaults(func=cli.train_info, pass_=["brand", "name", "date"])
|
|
253
274
|
|
|
275
|
+
stations = subparsers.add_parser("stations", aliases=["s", "find", "f", "stacje"], help="Allows you to find stations by their name")
|
|
276
|
+
stations.add_argument(
|
|
277
|
+
"query",
|
|
278
|
+
help="The station name",
|
|
279
|
+
default=None,
|
|
280
|
+
nargs="?",
|
|
281
|
+
)
|
|
282
|
+
stations.set_defaults(func=cli.find_station, pass_=["query"])
|
|
283
|
+
|
|
254
284
|
connections = subparsers.add_parser(
|
|
255
285
|
"connections",
|
|
256
|
-
aliases=["do", "z", "szukaj", "path"
|
|
286
|
+
aliases=["do", "z", "szukaj", "path"],
|
|
257
287
|
help="Allows you to search for connections from a to b",
|
|
258
288
|
)
|
|
259
289
|
connections.add_argument("start", help="The starting station", type=str)
|
|
@@ -291,6 +321,7 @@ def main():
|
|
|
291
321
|
client = KoleoAPI()
|
|
292
322
|
cli.client, cli.storage = client, storage
|
|
293
323
|
cli.console.no_color = args.nocolor
|
|
324
|
+
cli.no_color = args.nocolor
|
|
294
325
|
if hasattr(args, "station") and args.station is None:
|
|
295
326
|
args.station = storage.favourite_station
|
|
296
327
|
elif hasattr(args, "station") and args.save:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
koleo/__init__.py,sha256=N_IkOBZCSPCCw31Hu72CFys707PziGFmXpNVl0CXAz8,47
|
|
2
|
+
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
+
koleo/api.py,sha256=L4Nqcf2dj5IRNijxJ1IeJCf-69o_3FSjvJzLDi1f8s4,5435
|
|
4
|
+
koleo/cli.py,sha256=DAHe1Kqzkg0EGK00kkErBugtz-sdA8FNMpvdeAQoRvM,13767
|
|
5
|
+
koleo/storage.py,sha256=l48A8zsP3t77nFZA23dDncoeyV_VlhJ1RvM3xjWug2Q,2001
|
|
6
|
+
koleo/types.py,sha256=n7eXJfWD9BbCY6pwhPZhrArZsCqNSnGra2-ZSYwxJ58,3916
|
|
7
|
+
koleo/utils.py,sha256=N9ceKXsxC4RrG_W2PJopSL8Dsj44rFs2rDkyzM4m4ek,1428
|
|
8
|
+
koleo_cli-0.2.137.3.dist-info/METADATA,sha256=ONp3qsmOfzWqnTrgWcCGYIZHvuhwvo9l5tdUwrYO4lA,626
|
|
9
|
+
koleo_cli-0.2.137.3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
10
|
+
koleo_cli-0.2.137.3.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
11
|
+
koleo_cli-0.2.137.3.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
12
|
+
koleo_cli-0.2.137.3.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
koleo/__init__.py,sha256=N_IkOBZCSPCCw31Hu72CFys707PziGFmXpNVl0CXAz8,47
|
|
2
|
-
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
-
koleo/api.py,sha256=4qMx7pyfX_DR830BzfzwfWnmuiRQyvvWO42KwAl8Lqo,5422
|
|
4
|
-
koleo/cli.py,sha256=raS5fkz42YY3gVJXpoExid1Dkc99vmM-hPgTvHsUZGM,12742
|
|
5
|
-
koleo/storage.py,sha256=l48A8zsP3t77nFZA23dDncoeyV_VlhJ1RvM3xjWug2Q,2001
|
|
6
|
-
koleo/types.py,sha256=n7eXJfWD9BbCY6pwhPZhrArZsCqNSnGra2-ZSYwxJ58,3916
|
|
7
|
-
koleo/utils.py,sha256=N9ceKXsxC4RrG_W2PJopSL8Dsj44rFs2rDkyzM4m4ek,1428
|
|
8
|
-
koleo_cli-0.2.137.2.dist-info/METADATA,sha256=f980X6ifdRtYmDoq6-8lHz_Quz7pm4RZUlOI66OKVKw,626
|
|
9
|
-
koleo_cli-0.2.137.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
10
|
-
koleo_cli-0.2.137.2.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
11
|
-
koleo_cli-0.2.137.2.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
12
|
-
koleo_cli-0.2.137.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|