koleo-cli 0.2.137.12__tar.gz → 0.2.137.13__tar.gz

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: koleo-cli
3
- Version: 0.2.137.12
3
+ Version: 0.2.137.13
4
4
  Summary: Koleo CLI
5
5
  Home-page: https://github.com/lzgirlcat/koleo-cli
6
6
  Author: Zoey !
@@ -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(direct).lower(),
139
+ "query[only_purchasable]": str(purchasable).lower(),
140
140
  "query[only_direct]": str(direct).lower(),
141
141
  "query[brand_ids][]": brand_ids,
142
142
  }
@@ -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(self, start: str, end: str, date: datetime, brands: list[str], direct: bool, purchasable: bool):
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
- connections = self.client.get_connections(
243
- start_station["name_slug"], end_station["name_slug"], connection_brands, date, direct, purchasable
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 connections:
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.set_defaults(func=cli.connections, pass_=["start", "end", "brands", "date", "direct", "purchasable"])
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: koleo-cli
3
- Version: 0.2.137.12
3
+ Version: 0.2.137.13
4
4
  Summary: Koleo CLI
5
5
  Home-page: https://github.com/lzgirlcat/koleo-cli
6
6
  Author: Zoey !
@@ -14,7 +14,7 @@ def parse_requirements_file(path):
14
14
 
15
15
  setuptools.setup(
16
16
  name="koleo-cli",
17
- version="0.2.137.12",
17
+ version="0.2.137.13",
18
18
  description="Koleo CLI",
19
19
  long_description=long_description(),
20
20
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes