koleo-cli 0.2.137.9__py3-none-any.whl → 0.2.137.10__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/cli.py +54 -1
- koleo/storage.py +11 -2
- {koleo_cli-0.2.137.9.dist-info → koleo_cli-0.2.137.10.dist-info}/METADATA +1 -1
- koleo_cli-0.2.137.10.dist-info/RECORD +13 -0
- {koleo_cli-0.2.137.9.dist-info → koleo_cli-0.2.137.10.dist-info}/WHEEL +1 -1
- koleo_cli-0.2.137.9.dist-info/RECORD +0 -13
- {koleo_cli-0.2.137.9.dist-info → koleo_cli-0.2.137.10.dist-info}/LICENSE +0 -0
- {koleo_cli-0.2.137.9.dist-info → koleo_cli-0.2.137.10.dist-info}/entry_points.txt +0 -0
- {koleo_cli-0.2.137.9.dist-info → koleo_cli-0.2.137.10.dist-info}/top_level.txt +0 -0
koleo/cli.py
CHANGED
|
@@ -89,6 +89,37 @@ class CLI:
|
|
|
89
89
|
self.print(station_info)
|
|
90
90
|
self.get_arrivals(st["id"], date)
|
|
91
91
|
|
|
92
|
+
def all_trains(self, station: str, date: datetime):
|
|
93
|
+
st = self.get_station(station)
|
|
94
|
+
station_info = f"[bold blue][link=https://koleo.pl/dworzec-pkp/{st["name_slug"]}/{date.strftime("%Y-%m-%d")}]{st["name"]} at {date.strftime("%d-%m %H:%M")}[/bold blue] ID: {st["id"]}[/link]"
|
|
95
|
+
self.print(station_info)
|
|
96
|
+
arr_cache_id = f"arr-{st['id']}-{date.strftime("%Y-%m-%d")}"
|
|
97
|
+
dep_cache_id = f"dep-{st['id']}-{date.strftime("%Y-%m-%d")}"
|
|
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)
|
|
100
|
+
)
|
|
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)
|
|
103
|
+
)
|
|
104
|
+
trains = sorted(
|
|
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()
|
|
107
|
+
)
|
|
108
|
+
trains = [
|
|
109
|
+
(i, type)
|
|
110
|
+
for i, type in trains
|
|
111
|
+
if datetime.fromisoformat(i["departure"] if type == 1 else i["arrival"]).timestamp() > date.timestamp() # type: ignore
|
|
112
|
+
]
|
|
113
|
+
brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
114
|
+
parts = []
|
|
115
|
+
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]"
|
|
117
|
+
brand = next(iter(i for i in brands if i["id"] == train["brand_id"]), {}).get("logo_text")
|
|
118
|
+
parts.append(
|
|
119
|
+
f"{time} [red]{brand}[/red] {train["train_full_name"]}[purple] {train["stations"][0]["name"]} {self.format_position(train["platform"], train["track"])}[/purple]"
|
|
120
|
+
)
|
|
121
|
+
self.print("\n".join(parts))
|
|
122
|
+
|
|
92
123
|
def find_station(self, query: str | None):
|
|
93
124
|
if query:
|
|
94
125
|
stations = self.client.find_station(query)
|
|
@@ -356,6 +387,26 @@ def main():
|
|
|
356
387
|
arrivals.add_argument("-s", "--save", help="save the station as your default one", action="store_true")
|
|
357
388
|
arrivals.set_defaults(func=cli.full_arrivals, pass_=["station", "date"])
|
|
358
389
|
|
|
390
|
+
all_trains = subparsers.add_parser(
|
|
391
|
+
"all", aliases=["w", "wszystkie", "all_trains", "pociagi"], help="Allows you to list all station trains"
|
|
392
|
+
)
|
|
393
|
+
all_trains.add_argument(
|
|
394
|
+
"station",
|
|
395
|
+
help="The station name",
|
|
396
|
+
default=None,
|
|
397
|
+
nargs="*",
|
|
398
|
+
action=RemainderString,
|
|
399
|
+
)
|
|
400
|
+
all_trains.add_argument(
|
|
401
|
+
"-d",
|
|
402
|
+
"--date",
|
|
403
|
+
help="the date",
|
|
404
|
+
type=lambda s: parse_datetime(s),
|
|
405
|
+
default=datetime.now(),
|
|
406
|
+
)
|
|
407
|
+
all_trains.add_argument("-s", "--save", help="save the station as your default one", action="store_true")
|
|
408
|
+
all_trains.set_defaults(func=cli.all_trains, pass_=["station", "date"])
|
|
409
|
+
|
|
359
410
|
train_route = subparsers.add_parser(
|
|
360
411
|
"trainroute",
|
|
361
412
|
aliases=["r", "tr", "t", "poc", "pociąg"],
|
|
@@ -445,7 +496,6 @@ def main():
|
|
|
445
496
|
args.station = storage.favourite_station
|
|
446
497
|
elif hasattr(args, "station") and args.save:
|
|
447
498
|
storage.favourite_station = args.station
|
|
448
|
-
storage.save()
|
|
449
499
|
if not hasattr(args, "func"):
|
|
450
500
|
if storage.favourite_station:
|
|
451
501
|
cli.full_departures(storage.favourite_station, datetime.now())
|
|
@@ -454,3 +504,6 @@ def main():
|
|
|
454
504
|
exit()
|
|
455
505
|
else:
|
|
456
506
|
args.func(**{k: v for k, v in args.__dict__.items() if k in getattr(args, "pass_", [])})
|
|
507
|
+
|
|
508
|
+
if storage._dirty:
|
|
509
|
+
storage.save()
|
koleo/storage.py
CHANGED
|
@@ -33,6 +33,7 @@ class Storage:
|
|
|
33
33
|
|
|
34
34
|
def __post_init__(self):
|
|
35
35
|
self._path: str
|
|
36
|
+
self._dirty = False
|
|
36
37
|
|
|
37
38
|
@classmethod
|
|
38
39
|
def load(cls, *, path: str = DEFAULT_CONFIG_PATH) -> t.Self:
|
|
@@ -57,13 +58,13 @@ class Storage:
|
|
|
57
58
|
return item
|
|
58
59
|
else:
|
|
59
60
|
self.cache.pop(id)
|
|
60
|
-
self.
|
|
61
|
+
self._dirty = True
|
|
61
62
|
|
|
62
63
|
def set_cache(self, id: str, item: T, ttl: int = 86400) -> T:
|
|
63
64
|
if self.disable_cache:
|
|
64
65
|
return item
|
|
65
66
|
self.cache[id] = (int(time() + ttl), item)
|
|
66
|
-
self.
|
|
67
|
+
self._dirty = True
|
|
67
68
|
return item
|
|
68
69
|
|
|
69
70
|
def save(self):
|
|
@@ -72,4 +73,12 @@ class Storage:
|
|
|
72
73
|
if not ospath.exists(dir):
|
|
73
74
|
makedirs(dir)
|
|
74
75
|
with open(self._path, "w+") as f:
|
|
76
|
+
self.clean()
|
|
75
77
|
dump(asdict(self), f, indent=True)
|
|
78
|
+
|
|
79
|
+
def clean(self):
|
|
80
|
+
now = time()
|
|
81
|
+
copy = self.cache.copy()
|
|
82
|
+
self.cache = {k: data for k, data in copy.items() if data[0] > now}
|
|
83
|
+
if copy != self.cache:
|
|
84
|
+
self._dirty = True
|
|
@@ -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=07PSwLFmirdJ_JhPBJ7rO1nv_v90njIcwmOoxT4P_4M,5708
|
|
4
|
+
koleo/cli.py,sha256=CeZBwuS2ibZZ_HQq8bRwcY4HLq59_tEb9ux7daOvgc4,23239
|
|
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.10.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
9
|
+
koleo_cli-0.2.137.10.dist-info/METADATA,sha256=wwrlHORzN11td36xS_fjWglZpIWA11EryaJ6rpm9kXk,3096
|
|
10
|
+
koleo_cli-0.2.137.10.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
|
11
|
+
koleo_cli-0.2.137.10.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
12
|
+
koleo_cli-0.2.137.10.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
13
|
+
koleo_cli-0.2.137.10.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=_ahP1RWnlCtoM857fKZgbdO_eQQiuyDEdhYA2RoX784,20627
|
|
5
|
-
koleo/storage.py,sha256=_VztM8d3YTnmZOR9JvOsobThrQhb4gEzT1azC8N7baY,2024
|
|
6
|
-
koleo/types.py,sha256=pjVCIH39rUNeipazeRKOuTRCWoslLdbGivKiQmfd5Pw,5226
|
|
7
|
-
koleo/utils.py,sha256=CsYWNf3IPhHJln445tzXSA7r2z3NpmqVSmw8Rrb7YT0,1822
|
|
8
|
-
koleo_cli-0.2.137.9.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
9
|
-
koleo_cli-0.2.137.9.dist-info/METADATA,sha256=xfSWLLtbGywsL7CqQ9buD9bKWE1okzZyvo3kyWqyj2Q,3095
|
|
10
|
-
koleo_cli-0.2.137.9.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
11
|
-
koleo_cli-0.2.137.9.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
12
|
-
koleo_cli-0.2.137.9.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
13
|
-
koleo_cli-0.2.137.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|