koleo-cli 0.2.137.11__py3-none-any.whl → 0.2.137.13__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 +57 -18
- koleo/storage.py +1 -1
- {koleo_cli-0.2.137.11.dist-info → koleo_cli-0.2.137.13.dist-info}/METADATA +1 -1
- koleo_cli-0.2.137.13.dist-info/RECORD +13 -0
- {koleo_cli-0.2.137.11.dist-info → koleo_cli-0.2.137.13.dist-info}/WHEEL +1 -1
- koleo_cli-0.2.137.11.dist-info/RECORD +0 -13
- {koleo_cli-0.2.137.11.dist-info → koleo_cli-0.2.137.13.dist-info}/LICENSE +0 -0
- {koleo_cli-0.2.137.11.dist-info → koleo_cli-0.2.137.13.dist-info}/entry_points.txt +0 -0
- {koleo_cli-0.2.137.11.dist-info → koleo_cli-0.2.137.13.dist-info}/top_level.txt +0 -0
koleo/api.py
CHANGED
|
@@ -136,7 +136,7 @@ class KoleoAPI:
|
|
|
136
136
|
"query[date]": date.strftime("%d-%m-%Y %H:%M:%S"),
|
|
137
137
|
"query[start_station]": start,
|
|
138
138
|
"query[end_station]": end,
|
|
139
|
-
"query[only_purchasable]": str(
|
|
139
|
+
"query[only_purchasable]": str(purchasable).lower(),
|
|
140
140
|
"query[only_direct]": str(direct).lower(),
|
|
141
141
|
"query[brand_ids][]": brand_ids,
|
|
142
142
|
}
|
koleo/cli.py
CHANGED
|
@@ -96,14 +96,16 @@ class CLI:
|
|
|
96
96
|
arr_cache_id = f"arr-{st['id']}-{date.strftime("%Y-%m-%d")}"
|
|
97
97
|
dep_cache_id = f"dep-{st['id']}-{date.strftime("%Y-%m-%d")}"
|
|
98
98
|
arrivals = self.storage.get_cache(arr_cache_id) or self.storage.set_cache(
|
|
99
|
-
arr_cache_id, self.client.get_arrivals(st[
|
|
99
|
+
arr_cache_id, self.client.get_arrivals(st["id"], date)
|
|
100
100
|
)
|
|
101
101
|
departures = self.storage.get_cache(dep_cache_id) or self.storage.set_cache(
|
|
102
|
-
dep_cache_id, self.client.get_departures(st[
|
|
102
|
+
dep_cache_id, self.client.get_departures(st["id"], date)
|
|
103
103
|
)
|
|
104
104
|
trains = sorted(
|
|
105
105
|
[(i, 1) for i in departures] + [(i, 2) for i in arrivals],
|
|
106
|
-
key=lambda train: datetime.fromisoformat(
|
|
106
|
+
key=lambda train: datetime.fromisoformat(
|
|
107
|
+
train[0]["departure"] if train[1] == 1 else train[0]["arrival"]
|
|
108
|
+
).timestamp(),
|
|
107
109
|
)
|
|
108
110
|
trains = [
|
|
109
111
|
(i, type)
|
|
@@ -113,7 +115,11 @@ class CLI:
|
|
|
113
115
|
brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
114
116
|
parts = []
|
|
115
117
|
for train, type in trains:
|
|
116
|
-
time =
|
|
118
|
+
time = (
|
|
119
|
+
f"[bold green]{train['departure'][11:16]}[/bold green]"
|
|
120
|
+
if type == 1
|
|
121
|
+
else f"[bold yellow]{train['arrival'][11:16]}[/bold yellow]"
|
|
122
|
+
)
|
|
117
123
|
brand = next(iter(i for i in brands if i["id"] == train["brand_id"]), {}).get("logo_text")
|
|
118
124
|
parts.append(
|
|
119
125
|
f"{time} [red]{brand}[/red] {train["train_full_name"]}[purple] {train["stations"][0]["name"]} {self.format_position(train["platform"], train["track"])}[/purple]"
|
|
@@ -164,14 +170,16 @@ class CLI:
|
|
|
164
170
|
brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
165
171
|
for calendar in train_calendars:
|
|
166
172
|
brand = next(iter(i for i in brands if i["id"] == calendar["trainBrand"]), {}).get("logo_text", "")
|
|
167
|
-
parts = [
|
|
173
|
+
parts = [
|
|
174
|
+
f"[red]{brand}[/red] [bold blue]{calendar['train_nr']}{" "+ v if (v:=calendar.get("train_name")) else ""}[/bold blue]:"
|
|
175
|
+
]
|
|
168
176
|
for k, v in calendar["date_train_map"].items():
|
|
169
177
|
parts.append(f" [bold green]{k}[/bold green]: [purple]{v}[/purple]")
|
|
170
178
|
self.print("\n".join(parts))
|
|
171
179
|
|
|
172
180
|
def train_info(self, brand: str, name: str, date: datetime):
|
|
173
181
|
train_calendars = self.get_train_calendars(brand, name)
|
|
174
|
-
if not (train_id:=train_calendars[0]["date_train_map"].get(date.strftime("%Y-%m-%d"))):
|
|
182
|
+
if not (train_id := train_calendars[0]["date_train_map"].get(date.strftime("%Y-%m-%d"))):
|
|
175
183
|
self.print(f"[bold red]This train doesn't run on the selected date: {date.strftime("%Y-%m-%d")}[/bold red]")
|
|
176
184
|
exit(2)
|
|
177
185
|
self.train_detail(train_id)
|
|
@@ -182,7 +190,8 @@ class CLI:
|
|
|
182
190
|
brand = next(iter(i for i in brands if i["id"] == train_details["train"]["brand_id"]), {}).get("logo_text", "")
|
|
183
191
|
|
|
184
192
|
parts = [f"[red]{brand}[/red] [bold blue]{train_details["train"]["train_full_name"]}[/bold blue]"]
|
|
185
|
-
|
|
193
|
+
if train_details["train"]["run_desc"]:
|
|
194
|
+
parts.append(f" {train_details["train"]["run_desc"]}")
|
|
186
195
|
|
|
187
196
|
route_start = arr_dep_to_dt(train_details["stops"][0]["departure"])
|
|
188
197
|
route_end = arr_dep_to_dt(train_details["stops"][-1]["arrival"])
|
|
@@ -214,34 +223,57 @@ class CLI:
|
|
|
214
223
|
self.print("\n".join(parts))
|
|
215
224
|
self.print(self.train_route_table(train_details))
|
|
216
225
|
|
|
217
|
-
def connections(
|
|
226
|
+
def connections(
|
|
227
|
+
self,
|
|
228
|
+
start: str,
|
|
229
|
+
end: str,
|
|
230
|
+
date: datetime,
|
|
231
|
+
brands: list[str],
|
|
232
|
+
direct: bool,
|
|
233
|
+
purchasable: bool,
|
|
234
|
+
length: int = 1
|
|
235
|
+
):
|
|
218
236
|
start_station = self.get_station(start)
|
|
219
237
|
end_station = self.get_station(end)
|
|
220
238
|
brands = [i.lower().strip() for i in brands]
|
|
221
239
|
api_brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
222
240
|
if not brands:
|
|
223
|
-
connection_brands = [i["id"] for i in api_brands
|
|
241
|
+
connection_brands = {i["name"]: i["id"] for i in api_brands}
|
|
224
242
|
else:
|
|
225
|
-
connection_brands =
|
|
226
|
-
i["id"]
|
|
243
|
+
connection_brands = {
|
|
244
|
+
i["name"]:i["id"]
|
|
227
245
|
for i in api_brands
|
|
228
246
|
if i["name"].lower().strip() in brands or i["logo_text"].lower().strip() in brands
|
|
229
|
-
|
|
247
|
+
}
|
|
230
248
|
if not connection_brands:
|
|
231
249
|
self.print(f'[bold red]No brands match: "{', '.join(brands)}"[/bold red]')
|
|
232
250
|
exit(2)
|
|
233
|
-
|
|
234
|
-
|
|
251
|
+
results = []
|
|
252
|
+
fetch_date = date
|
|
253
|
+
while len(results) < length:
|
|
254
|
+
connections = self.client.get_connections(
|
|
255
|
+
start_station["name_slug"], end_station["name_slug"], list(connection_brands.values()), fetch_date, direct, purchasable
|
|
256
|
+
)
|
|
257
|
+
if connections:
|
|
258
|
+
fetch_date = arr_dep_to_dt(connections[-1]["departure"]) + timedelta(seconds=(30*60)+1) # wtf
|
|
259
|
+
results.extend(connections)
|
|
260
|
+
else:
|
|
261
|
+
break
|
|
262
|
+
link = (
|
|
263
|
+
f"https://koleo.pl/rozklad-pkp/{start_station["name_slug"]}/{end_station["name_slug"]}"
|
|
264
|
+
+ f"/{date.strftime("%d-%m-%Y_%H:%M")}"
|
|
265
|
+
+f"{"all" if not direct else "direct"}/{"-".join(connection_brands.keys()) if brands else "all"}"
|
|
235
266
|
)
|
|
236
267
|
parts = [
|
|
237
|
-
f"[bold blue]{start_station["name"]} → {end_station["name"]} at {date.strftime("%H:%M %d-%m")}[/bold blue]"
|
|
268
|
+
f"[bold blue][link={link}]{start_station["name"]} → {end_station["name"]} at {date.strftime("%H:%M %d-%m")}[/link][/bold blue]"
|
|
238
269
|
]
|
|
239
|
-
for i in
|
|
270
|
+
for i in results:
|
|
240
271
|
arr = arr_dep_to_dt(i["arrival"])
|
|
241
272
|
dep = arr_dep_to_dt(i["departure"])
|
|
242
273
|
travel_time = (arr - dep).seconds
|
|
274
|
+
date_part = f"{arr.strftime("%d-%m")} " if arr.date() != date.date() else ""
|
|
243
275
|
parts.append(
|
|
244
|
-
f"[bold green][link=https://koleo.pl/travel-options/{i["id"]}]{dep.strftime("%H:%M")} - {arr.strftime("%H:%M")}[/bold green] {travel_time//3600}h{(travel_time % 3600)/60:.0f}m {i['distance']}km:[/link]"
|
|
276
|
+
f"[bold green][link=https://koleo.pl/travel-options/{i["id"]}]{date_part}{dep.strftime("%H:%M")} - {arr.strftime("%H:%M")}[/bold green] {travel_time//3600}h{(travel_time % 3600)/60:.0f}m {i['distance']}km:[/link]"
|
|
245
277
|
)
|
|
246
278
|
if len(i["trains"]) == 1:
|
|
247
279
|
train = i["trains"][0]
|
|
@@ -485,7 +517,14 @@ def main():
|
|
|
485
517
|
action="store_true",
|
|
486
518
|
default=False,
|
|
487
519
|
)
|
|
488
|
-
connections.
|
|
520
|
+
connections.add_argument(
|
|
521
|
+
"-l",
|
|
522
|
+
"--length",
|
|
523
|
+
help="fetch at least n connections",
|
|
524
|
+
type=int,
|
|
525
|
+
default=1,
|
|
526
|
+
)
|
|
527
|
+
connections.set_defaults(func=cli.connections, pass_=["start", "end", "brands", "date", "direct", "purchasable", "length"])
|
|
489
528
|
|
|
490
529
|
args = parser.parse_args()
|
|
491
530
|
|
koleo/storage.py
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
koleo/__init__.py,sha256=N_IkOBZCSPCCw31Hu72CFys707PziGFmXpNVl0CXAz8,47
|
|
2
|
+
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
+
koleo/api.py,sha256=J05sdOg0S0VgcJNcmmoE8fYMKVVmtqkw5Sy88e-C91k,5713
|
|
4
|
+
koleo/cli.py,sha256=o2Ixo9uegZ7VHL98SoV49Vn2U1VyBp2sqFFZGsbvBb0,24692
|
|
5
|
+
koleo/storage.py,sha256=L31IrXxdWiGGOraVBdFeHc1Z-a2fNvyRn-uC7gJWe9E,2305
|
|
6
|
+
koleo/types.py,sha256=pjVCIH39rUNeipazeRKOuTRCWoslLdbGivKiQmfd5Pw,5226
|
|
7
|
+
koleo/utils.py,sha256=CsYWNf3IPhHJln445tzXSA7r2z3NpmqVSmw8Rrb7YT0,1822
|
|
8
|
+
koleo_cli-0.2.137.13.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
9
|
+
koleo_cli-0.2.137.13.dist-info/METADATA,sha256=tfDdMmERJgsghRGiM0O8yu_qjbawpD6EUb9FDyiSMeE,3096
|
|
10
|
+
koleo_cli-0.2.137.13.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
11
|
+
koleo_cli-0.2.137.13.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
12
|
+
koleo_cli-0.2.137.13.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
13
|
+
koleo_cli-0.2.137.13.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
koleo/__init__.py,sha256=N_IkOBZCSPCCw31Hu72CFys707PziGFmXpNVl0CXAz8,47
|
|
2
|
-
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
-
koleo/api.py,sha256=07PSwLFmirdJ_JhPBJ7rO1nv_v90njIcwmOoxT4P_4M,5708
|
|
4
|
-
koleo/cli.py,sha256=ixTi_44y-j4Yf_cgpZz-9iI5sH1pdyaqHRV-WtqzLbQ,23500
|
|
5
|
-
koleo/storage.py,sha256=U1ydt8AZ3WsiNBOmThD-cxomLzLrpHRG4BZbMg-14Fc,2304
|
|
6
|
-
koleo/types.py,sha256=pjVCIH39rUNeipazeRKOuTRCWoslLdbGivKiQmfd5Pw,5226
|
|
7
|
-
koleo/utils.py,sha256=CsYWNf3IPhHJln445tzXSA7r2z3NpmqVSmw8Rrb7YT0,1822
|
|
8
|
-
koleo_cli-0.2.137.11.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
9
|
-
koleo_cli-0.2.137.11.dist-info/METADATA,sha256=G2q-fowwyDNeu6aY9osXfKDV8vZu9VKJa0CB46NoifY,3096
|
|
10
|
-
koleo_cli-0.2.137.11.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
11
|
-
koleo_cli-0.2.137.11.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
12
|
-
koleo_cli-0.2.137.11.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
13
|
-
koleo_cli-0.2.137.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|