koleo-cli 0.2.137.12__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 +41 -11
- {koleo_cli-0.2.137.12.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.12.dist-info → koleo_cli-0.2.137.13.dist-info}/WHEEL +1 -1
- koleo_cli-0.2.137.12.dist-info/RECORD +0 -13
- {koleo_cli-0.2.137.12.dist-info → koleo_cli-0.2.137.13.dist-info}/LICENSE +0 -0
- {koleo_cli-0.2.137.12.dist-info → koleo_cli-0.2.137.13.dist-info}/entry_points.txt +0 -0
- {koleo_cli-0.2.137.12.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
|
@@ -223,34 +223,57 @@ class CLI:
|
|
|
223
223
|
self.print("\n".join(parts))
|
|
224
224
|
self.print(self.train_route_table(train_details))
|
|
225
225
|
|
|
226
|
-
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
|
+
):
|
|
227
236
|
start_station = self.get_station(start)
|
|
228
237
|
end_station = self.get_station(end)
|
|
229
238
|
brands = [i.lower().strip() for i in brands]
|
|
230
239
|
api_brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
231
240
|
if not brands:
|
|
232
|
-
connection_brands = [i["id"] for i in api_brands
|
|
241
|
+
connection_brands = {i["name"]: i["id"] for i in api_brands}
|
|
233
242
|
else:
|
|
234
|
-
connection_brands =
|
|
235
|
-
i["id"]
|
|
243
|
+
connection_brands = {
|
|
244
|
+
i["name"]:i["id"]
|
|
236
245
|
for i in api_brands
|
|
237
246
|
if i["name"].lower().strip() in brands or i["logo_text"].lower().strip() in brands
|
|
238
|
-
|
|
247
|
+
}
|
|
239
248
|
if not connection_brands:
|
|
240
249
|
self.print(f'[bold red]No brands match: "{', '.join(brands)}"[/bold red]')
|
|
241
250
|
exit(2)
|
|
242
|
-
|
|
243
|
-
|
|
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"}"
|
|
244
266
|
)
|
|
245
267
|
parts = [
|
|
246
|
-
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]"
|
|
247
269
|
]
|
|
248
|
-
for i in
|
|
270
|
+
for i in results:
|
|
249
271
|
arr = arr_dep_to_dt(i["arrival"])
|
|
250
272
|
dep = arr_dep_to_dt(i["departure"])
|
|
251
273
|
travel_time = (arr - dep).seconds
|
|
274
|
+
date_part = f"{arr.strftime("%d-%m")} " if arr.date() != date.date() else ""
|
|
252
275
|
parts.append(
|
|
253
|
-
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]"
|
|
254
277
|
)
|
|
255
278
|
if len(i["trains"]) == 1:
|
|
256
279
|
train = i["trains"][0]
|
|
@@ -494,7 +517,14 @@ def main():
|
|
|
494
517
|
action="store_true",
|
|
495
518
|
default=False,
|
|
496
519
|
)
|
|
497
|
-
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"])
|
|
498
528
|
|
|
499
529
|
args = parser.parse_args()
|
|
500
530
|
|
|
@@ -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=5QmvtqjB7kirt1iEG5SZDzOV6QTHTiJMNRtJoZa2Jik,23678
|
|
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.12.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
9
|
-
koleo_cli-0.2.137.12.dist-info/METADATA,sha256=WAaZyvFSeL7O3M2Ss9YNz2SyyPTW3m7tzU8KKdY-pnY,3096
|
|
10
|
-
koleo_cli-0.2.137.12.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
|
11
|
-
koleo_cli-0.2.137.12.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
12
|
-
koleo_cli-0.2.137.12.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
13
|
-
koleo_cli-0.2.137.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|