koleo-cli 0.2.137.11__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.11
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
  }
@@ -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['id'], date)
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['id'], date)
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(train[0]["departure"] if train[1] == 1 else train[0]["arrival"]).timestamp()
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 = f"[bold green]{train['departure'][11:16]}[/bold green]" if type == 1 else f"[bold yellow]{train['arrival'][11:16]}[/bold yellow]"
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 = [f"[red]{brand}[/red] [bold blue]{calendar['train_nr']}{" "+ v if (v:=calendar.get("train_name")) else ""}[/bold blue]:"]
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
- parts.append(f" {train_details["train"]["run_desc"]}")
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(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
+ ):
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
- connections = self.client.get_connections(
234
- 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"}"
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 connections:
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.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"])
489
528
 
490
529
  args = parser.parse_args()
491
530
 
@@ -81,4 +81,4 @@ class Storage:
81
81
  copy = self.cache.copy()
82
82
  self.cache = {k: data for k, data in copy.items() if data[0] > now}
83
83
  if copy != self.cache:
84
- self._dirty = True
84
+ self._dirty = True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: koleo-cli
3
- Version: 0.2.137.11
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.11",
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