koleo-cli 0.2.137.1__py3-none-any.whl → 0.2.137.2__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/__init__.py +1 -3
- koleo/api.py +46 -34
- koleo/cli.py +106 -33
- koleo/storage.py +9 -9
- koleo/types.py +7 -0
- koleo/utils.py +11 -7
- {koleo_cli-0.2.137.1.dist-info → koleo_cli-0.2.137.2.dist-info}/METADATA +1 -1
- koleo_cli-0.2.137.2.dist-info/RECORD +12 -0
- {koleo_cli-0.2.137.1.dist-info → koleo_cli-0.2.137.2.dist-info}/WHEEL +1 -1
- koleo_cli-0.2.137.1.dist-info/RECORD +0 -12
- {koleo_cli-0.2.137.1.dist-info → koleo_cli-0.2.137.2.dist-info}/entry_points.txt +0 -0
- {koleo_cli-0.2.137.1.dist-info → koleo_cli-0.2.137.2.dist-info}/top_level.txt +0 -0
koleo/__init__.py
CHANGED
koleo/api.py
CHANGED
|
@@ -1,53 +1,59 @@
|
|
|
1
1
|
import typing as t
|
|
2
2
|
from datetime import datetime
|
|
3
3
|
|
|
4
|
-
from requests import
|
|
4
|
+
from requests import PreparedRequest, Response, Session
|
|
5
5
|
|
|
6
6
|
from koleo.types import *
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
class KoleoAPIException(Exception):
|
|
10
|
-
status: int
|
|
11
|
-
request: PreparedRequest
|
|
12
|
-
response: Response
|
|
13
9
|
|
|
14
|
-
def __init__(self, response: Response, *args: object) -> None:
|
|
15
|
-
super().__init__(*args)
|
|
16
|
-
self.status = response.status_code
|
|
17
|
-
self.request = response.request
|
|
18
|
-
self.response = response
|
|
19
10
|
|
|
20
|
-
@classmethod
|
|
21
|
-
def from_response(cls, response: Response) -> "KoleoAPIException":
|
|
22
|
-
if response.status_code == 404:
|
|
23
|
-
return KoleoNotFound(response)
|
|
24
|
-
elif response.status_code == 401:
|
|
25
|
-
return KoleoUnauthorized(response)
|
|
26
|
-
elif response.status_code == 403:
|
|
27
|
-
return KoleoForbidden(response)
|
|
28
|
-
elif response.status_code == 429:
|
|
29
|
-
return KoleoRatelimited(response)
|
|
30
|
-
else:
|
|
31
|
-
return KoleoAPIException(response)
|
|
32
11
|
|
|
33
12
|
|
|
34
|
-
class KoleoNotFound(KoleoAPIException):
|
|
35
|
-
pass
|
|
36
13
|
|
|
14
|
+
class errors:
|
|
15
|
+
class KoleoAPIException(Exception):
|
|
16
|
+
status: int
|
|
17
|
+
request: PreparedRequest
|
|
18
|
+
response: Response
|
|
37
19
|
|
|
38
|
-
|
|
39
|
-
|
|
20
|
+
def __init__(self, response: Response, *args: object) -> None:
|
|
21
|
+
super().__init__(*args)
|
|
22
|
+
self.status = response.status_code
|
|
23
|
+
self.request = response.request
|
|
24
|
+
self.response = response
|
|
40
25
|
|
|
26
|
+
@classmethod
|
|
27
|
+
def from_response(cls, response: Response) -> "t.Self":
|
|
28
|
+
if response.status_code == 404:
|
|
29
|
+
return errors.KoleoNotFound(response)
|
|
30
|
+
elif response.status_code == 401:
|
|
31
|
+
return errors.KoleoUnauthorized(response)
|
|
32
|
+
elif response.status_code == 403:
|
|
33
|
+
return errors.KoleoForbidden(response)
|
|
34
|
+
elif response.status_code == 429:
|
|
35
|
+
return errors.KoleoRatelimited(response)
|
|
36
|
+
else:
|
|
37
|
+
return cls(response)
|
|
41
38
|
|
|
42
|
-
class
|
|
43
|
-
|
|
39
|
+
class KoleoNotFound(KoleoAPIException):
|
|
40
|
+
pass
|
|
44
41
|
|
|
42
|
+
class KoleoForbidden(KoleoAPIException):
|
|
43
|
+
pass
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
|
|
46
|
+
class KoleoUnauthorized(KoleoAPIException):
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class KoleoRatelimited(KoleoAPIException):
|
|
51
|
+
pass
|
|
48
52
|
|
|
49
53
|
|
|
50
54
|
class KoleoAPI:
|
|
55
|
+
errors = errors
|
|
56
|
+
|
|
51
57
|
def __init__(self) -> None:
|
|
52
58
|
self.session = Session()
|
|
53
59
|
self.base_url = "https://koleo.pl"
|
|
@@ -61,17 +67,23 @@ class KoleoAPI:
|
|
|
61
67
|
headers = {**self.base_headers, **kwargs.get("headers", {})}
|
|
62
68
|
r = self.session.get(self.base_url + path, *args, headers=headers, **kwargs)
|
|
63
69
|
if not r.ok:
|
|
64
|
-
raise KoleoAPIException.from_response(r)
|
|
70
|
+
raise errors.KoleoAPIException.from_response(r)
|
|
65
71
|
return r
|
|
66
72
|
|
|
67
73
|
def _get_json(self, path, *args, **kwargs) -> t.Any:
|
|
68
74
|
r = self._get(path, *args, **kwargs)
|
|
69
|
-
|
|
75
|
+
res = r.json()
|
|
76
|
+
if res is None:
|
|
77
|
+
raise self.errors.KoleoNotFound(r)
|
|
78
|
+
return res
|
|
70
79
|
|
|
71
80
|
def _get_bytes(self, path, *args, **kwargs) -> bytes:
|
|
72
81
|
r = self._get(path, *args, **kwargs)
|
|
73
82
|
return r.content
|
|
74
83
|
|
|
84
|
+
def get_stations(self) -> list[ExtendedStationInfo]:
|
|
85
|
+
return self._get_json("/api/v2/main/stations")
|
|
86
|
+
|
|
75
87
|
def find_station(self, query: str, language: str = "pl") -> list[ExtendedStationInfo]:
|
|
76
88
|
# https://koleo.pl/ls?q=tere&language=pl
|
|
77
89
|
return self._get_json("/ls", query={"q": query, "language": language})
|
|
@@ -119,7 +131,7 @@ class KoleoAPI:
|
|
|
119
131
|
brand_ids: list[int],
|
|
120
132
|
date: datetime,
|
|
121
133
|
direct: bool = False,
|
|
122
|
-
purchasable: bool = False
|
|
134
|
+
purchasable: bool = False,
|
|
123
135
|
) -> ...:
|
|
124
136
|
params = {
|
|
125
137
|
"query[date]": date.strftime("%d-%m-%Y %H:%M:%S"),
|
|
@@ -127,7 +139,7 @@ class KoleoAPI:
|
|
|
127
139
|
"query[end_station]": end,
|
|
128
140
|
"query[only_purchasable]": purchasable,
|
|
129
141
|
"query[direct]": direct,
|
|
130
|
-
"query[brand_ids]": brand_ids
|
|
142
|
+
"query[brand_ids][]": brand_ids,
|
|
131
143
|
}
|
|
132
144
|
return self._get_json("/api/v2/main/connections", params=params)
|
|
133
145
|
|
koleo/cli.py
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
1
|
from argparse import ArgumentParser
|
|
2
|
+
from datetime import datetime, timedelta
|
|
3
3
|
|
|
4
4
|
from rich.console import Console
|
|
5
5
|
from rich.traceback import install
|
|
6
6
|
|
|
7
7
|
from .api import KoleoAPI
|
|
8
|
-
from .
|
|
9
|
-
from .
|
|
10
|
-
from .
|
|
8
|
+
from .storage import DEFAULT_CONFIG_PATH, Storage
|
|
9
|
+
from .types import TrainDetailResponse, TrainOnStationInfo, ExtendedBaseStationInfo
|
|
10
|
+
from .utils import convert_platform_number, name_to_slug, parse_datetime, arr_dep_to_dt
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
install(show_locals=False, max_frames=2)
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class CLI:
|
|
@@ -43,10 +44,15 @@ class CLI:
|
|
|
43
44
|
def storage(self, storage: Storage):
|
|
44
45
|
self._storage = storage
|
|
45
46
|
|
|
46
|
-
def list_stations(self, name: str):
|
|
47
|
+
def list_stations(self, name: str):
|
|
48
|
+
...
|
|
47
49
|
|
|
48
50
|
def get_departures(self, station_id: int, date: datetime):
|
|
49
|
-
|
|
51
|
+
cache_id = f"dep-{station_id}-{date.strftime("%Y-%m-%d")}"
|
|
52
|
+
trains = (
|
|
53
|
+
self.storage.get_cache(cache_id) or
|
|
54
|
+
self.storage.set_cache(cache_id, self.client.get_departures(station_id, date))
|
|
55
|
+
)
|
|
50
56
|
trains = [
|
|
51
57
|
i
|
|
52
58
|
for i in trains
|
|
@@ -57,7 +63,11 @@ class CLI:
|
|
|
57
63
|
return table
|
|
58
64
|
|
|
59
65
|
def get_arrivals(self, station_id: int, date: datetime):
|
|
60
|
-
|
|
66
|
+
cache_id = f"arr-{station_id}-{date.strftime("%Y-%m-%d")}"
|
|
67
|
+
trains = (
|
|
68
|
+
self.storage.get_cache(cache_id) or
|
|
69
|
+
self.storage.set_cache(cache_id, self.client.get_arrivals(station_id, date))
|
|
70
|
+
)
|
|
61
71
|
trains = [
|
|
62
72
|
i
|
|
63
73
|
for i in trains
|
|
@@ -68,19 +78,13 @@ class CLI:
|
|
|
68
78
|
return table
|
|
69
79
|
|
|
70
80
|
def full_departures(self, station: str, date: datetime):
|
|
71
|
-
|
|
72
|
-
st = self.storage.get_cache(f"st-{slug}") or self.storage.set_cache(
|
|
73
|
-
f"st-{slug}", self.client.get_station_by_slug(slug)
|
|
74
|
-
)
|
|
81
|
+
st = self.get_station(station)
|
|
75
82
|
station_info = f"[bold blue]{st["name"]}[/bold blue] ID: {st["id"]}"
|
|
76
83
|
self.console.print(station_info)
|
|
77
84
|
self.get_departures(st["id"], date)
|
|
78
85
|
|
|
79
86
|
def full_arrivals(self, station: str, date: datetime):
|
|
80
|
-
|
|
81
|
-
st = self.storage.get_cache(f"st-{slug}") or self.storage.set_cache(
|
|
82
|
-
f"st-{slug}", self.client.get_station_by_slug(slug)
|
|
83
|
-
)
|
|
87
|
+
st = self.get_station(station)
|
|
84
88
|
station_info = f"[bold blue]{st["name"]}[/bold blue] ID: {st["id"]}"
|
|
85
89
|
self.console.print(station_info)
|
|
86
90
|
self.get_arrivals(st["id"], date)
|
|
@@ -96,15 +100,27 @@ class CLI:
|
|
|
96
100
|
number = int(number)
|
|
97
101
|
else:
|
|
98
102
|
raise ValueError("Invalid train name!")
|
|
103
|
+
brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
104
|
+
if brand not in [i["name"] for i in brands]:
|
|
105
|
+
res = {i["logo_text"]: i["name"] for i in brands}.get(brand)
|
|
106
|
+
if not res:
|
|
107
|
+
raise ValueError("Invalid brand name!")
|
|
108
|
+
brand = res
|
|
99
109
|
cache_id = f"tc-{brand}-{number}-{name}"
|
|
100
110
|
train_calendars = self.storage.get_cache(cache_id) or self.storage.set_cache(
|
|
101
111
|
cache_id, self.client.get_train_calendars(brand, number, train_name)
|
|
102
112
|
)
|
|
103
|
-
brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
104
113
|
train_id = train_calendars["train_calendars"][0]["date_train_map"][date.strftime("%Y-%m-%d")]
|
|
105
114
|
train_details = self.client.get_train(train_id)
|
|
106
|
-
brand = next(iter(i for i in brands if i["id"] == train_details["train"]["brand_id"]), {}).get("
|
|
115
|
+
brand = next(iter(i for i in brands if i["id"] == train_details["train"]["brand_id"]), {}).get("logo_text", "")
|
|
107
116
|
parts = [f"{brand} {train_details["train"]["train_full_name"]}"]
|
|
117
|
+
route_start = arr_dep_to_dt(train_details["stops"][0]["departure"])
|
|
118
|
+
route_end = arr_dep_to_dt(train_details["stops"][-1]["arrival"])
|
|
119
|
+
if route_end.hour < route_start.hour or (route_end.hour==route_start.hour and route_end.minute < route_end.minute):
|
|
120
|
+
route_end += timedelta(days=1)
|
|
121
|
+
travel_time = route_end - route_start
|
|
122
|
+
speed = train_details["stops"][-1]["distance"] / 1000 / travel_time.seconds * 3600
|
|
123
|
+
parts.append(f"[white] {travel_time.seconds//3600}h{(travel_time.seconds % 3600)/60:.0f}m {speed:^4.1f}km/h [/white]")
|
|
108
124
|
vehicle_types: dict[str, str] = {
|
|
109
125
|
stop["station_display_name"]: stop["vehicle_type"]
|
|
110
126
|
for stop in train_details["stops"]
|
|
@@ -121,14 +137,26 @@ class CLI:
|
|
|
121
137
|
self.console.print("\n".join(parts))
|
|
122
138
|
self.console.print(self.train_route_table(train_details))
|
|
123
139
|
|
|
124
|
-
def
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
140
|
+
def connections(self, start: str, end: str, date: datetime, brands: list[str], direct: bool = False, purchasable: bool = False):
|
|
141
|
+
start_station = self.get_station(start)
|
|
142
|
+
end_station = self.get_station(end)
|
|
143
|
+
brands = [i.lower().strip() for i in brands]
|
|
144
|
+
api_brands = self.storage.get_cache("brands") or self.storage.set_cache("brands", self.client.get_brands())
|
|
145
|
+
if not brands:
|
|
146
|
+
connection_brands = [i["id"] for i in api_brands]
|
|
147
|
+
else:
|
|
148
|
+
connection_brands = [i["id"] for i in api_brands if i["name"].lower().strip() in brands or i["logo_text"].lower().strip() in brands]
|
|
149
|
+
if not connection_brands:
|
|
150
|
+
self.console.print(f'[bold red]No brands match: "{', '.join(brands)}"[/bold red]')
|
|
151
|
+
exit(2)
|
|
152
|
+
connections = self.client.get_connections(
|
|
153
|
+
start_station["name_slug"],
|
|
154
|
+
end_station["name_slug"],
|
|
155
|
+
connection_brands,
|
|
156
|
+
date,
|
|
157
|
+
direct,
|
|
158
|
+
purchasable
|
|
128
159
|
)
|
|
129
|
-
station_info = f"[bold blue]{st["name"]}[/bold blue] ID: {st["id"]}"
|
|
130
|
-
self.console.print(station_info)
|
|
131
|
-
self.get_arrivals(st["id"], date)
|
|
132
160
|
|
|
133
161
|
def trains_on_station_table(self, trains: list[TrainOnStationInfo], type: int = 1):
|
|
134
162
|
parts = []
|
|
@@ -136,23 +164,34 @@ class CLI:
|
|
|
136
164
|
for train in trains:
|
|
137
165
|
time = train["departure"] if type == 1 else train["arrival"]
|
|
138
166
|
assert time
|
|
139
|
-
brand = next(iter(i for i in brands if i["id"] == train["brand_id"]), {}).get("
|
|
167
|
+
brand = next(iter(i for i in brands if i["id"] == train["brand_id"]), {}).get("logo_text")
|
|
168
|
+
platform = convert_platform_number(train["platform"]) if train["platform"] else ""
|
|
169
|
+
position_info = f"{platform}/{train["track"]}" if train["track"] else platform
|
|
140
170
|
parts.append(
|
|
141
|
-
f"[bold green]{time[11:16]}[/bold green] {brand} {train["train_full_name"]}[purple] {train["stations"][0]["name"]} [/purple]"
|
|
171
|
+
f"[bold green]{time[11:16]}[/bold green] {brand} {train["train_full_name"]}[purple] {train["stations"][0]["name"]} {position_info}[/purple]"
|
|
142
172
|
)
|
|
143
173
|
return "\n".join(parts)
|
|
144
174
|
|
|
145
175
|
def train_route_table(self, train: TrainDetailResponse):
|
|
146
176
|
parts = []
|
|
147
177
|
for stop in train["stops"]:
|
|
148
|
-
arr =
|
|
149
|
-
dep =
|
|
178
|
+
arr = arr_dep_to_dt(stop["arrival"])
|
|
179
|
+
dep = arr_dep_to_dt(stop["departure"])
|
|
150
180
|
platform = convert_platform_number(stop["platform"]) or ""
|
|
151
181
|
parts.append(
|
|
152
182
|
f"[white underline]{stop["distance"] / 1000:^5.1f}km[/white underline] [bold green]{arr.strftime("%H:%M")}[/bold green] - [bold red]{dep.strftime("%H:%M")}[/bold red] [purple]{stop["station_display_name"]} {platform} [/purple]"
|
|
153
183
|
)
|
|
154
184
|
return "\n".join(parts)
|
|
155
185
|
|
|
186
|
+
def get_station(self, station: str) -> ExtendedBaseStationInfo:
|
|
187
|
+
slug = name_to_slug(station)
|
|
188
|
+
try:
|
|
189
|
+
return self.storage.get_cache(f"st-{slug}") or self.storage.set_cache(
|
|
190
|
+
f"st-{slug}", self.client.get_station_by_slug(slug)
|
|
191
|
+
)
|
|
192
|
+
except self.client.errors.KoleoNotFound:
|
|
193
|
+
self.console.print(f'[bold red]Station not found: "{station}"[/bold red]')
|
|
194
|
+
exit(2)
|
|
156
195
|
|
|
157
196
|
def main():
|
|
158
197
|
cli = CLI()
|
|
@@ -160,9 +199,9 @@ def main():
|
|
|
160
199
|
parser = ArgumentParser("koleo", description="Koleo CLI")
|
|
161
200
|
parser.add_argument("-c", "--config", help="Custom config path.", default=DEFAULT_CONFIG_PATH)
|
|
162
201
|
parser.add_argument("--nocolor", help="Disable color output", action="store_true", default=False)
|
|
163
|
-
subparsers = parser.add_subparsers(title="actions", required=False)
|
|
202
|
+
subparsers = parser.add_subparsers(title="actions", required=False) # type: ignore
|
|
164
203
|
|
|
165
|
-
departures = subparsers.add_parser("departures", aliases=["d", "dep"], help="Allows you to list station departures")
|
|
204
|
+
departures = subparsers.add_parser("departures", aliases=["d", "dep", "odjazdy", "o"], help="Allows you to list station departures")
|
|
166
205
|
departures.add_argument(
|
|
167
206
|
"station",
|
|
168
207
|
help="The station name",
|
|
@@ -179,7 +218,7 @@ def main():
|
|
|
179
218
|
departures.add_argument("-s", "--save", help="save the station as your default one", action="store_true")
|
|
180
219
|
departures.set_defaults(func=cli.full_departures, pass_=["station", "date"])
|
|
181
220
|
|
|
182
|
-
arrivals = subparsers.add_parser("arrivals", aliases=["a", "arr"], help="Allows you to list station departures")
|
|
221
|
+
arrivals = subparsers.add_parser("arrivals", aliases=["a", "arr", "przyjazdy", "p"], help="Allows you to list station departures")
|
|
183
222
|
arrivals.add_argument(
|
|
184
223
|
"station",
|
|
185
224
|
help="The station name",
|
|
@@ -198,7 +237,7 @@ def main():
|
|
|
198
237
|
|
|
199
238
|
train_route = subparsers.add_parser(
|
|
200
239
|
"trainroute",
|
|
201
|
-
aliases=["r", "tr", "t"],
|
|
240
|
+
aliases=["r", "tr", "t", "poc", "pociąg"],
|
|
202
241
|
help="Allows you to show the train's route",
|
|
203
242
|
)
|
|
204
243
|
train_route.add_argument("brand", help="The brand name", type=str)
|
|
@@ -212,6 +251,40 @@ def main():
|
|
|
212
251
|
)
|
|
213
252
|
train_route.set_defaults(func=cli.train_info, pass_=["brand", "name", "date"])
|
|
214
253
|
|
|
254
|
+
connections = subparsers.add_parser(
|
|
255
|
+
"connections",
|
|
256
|
+
aliases=["do", "z", "szukaj", "path", "find"],
|
|
257
|
+
help="Allows you to search for connections from a to b",
|
|
258
|
+
)
|
|
259
|
+
connections.add_argument("start", help="The starting station", type=str)
|
|
260
|
+
connections.add_argument("end", help="The end station", type=str)
|
|
261
|
+
connections.add_argument(
|
|
262
|
+
"-d",
|
|
263
|
+
"--date",
|
|
264
|
+
help="the date",
|
|
265
|
+
type=lambda s: parse_datetime(s),
|
|
266
|
+
default=datetime.now(),
|
|
267
|
+
)
|
|
268
|
+
connections.add_argument(
|
|
269
|
+
"-b",
|
|
270
|
+
"--brands",
|
|
271
|
+
help="Brands to include",
|
|
272
|
+
action="extend", nargs="+", type=str, default=[]
|
|
273
|
+
)
|
|
274
|
+
connections.add_argument(
|
|
275
|
+
"-f",
|
|
276
|
+
"--direct",
|
|
277
|
+
help="whether or not the result should only include direct trains",
|
|
278
|
+
action="store_true", default=False
|
|
279
|
+
)
|
|
280
|
+
connections.add_argument(
|
|
281
|
+
"-p",
|
|
282
|
+
"--purchasable",
|
|
283
|
+
help="whether or not the result should only trains purchasable on koleo",
|
|
284
|
+
action="store_true", default=False
|
|
285
|
+
)
|
|
286
|
+
connections.set_defaults(func=cli.connections, pass_=["start", "end", "brands", "date", "direct" "purchasable"])
|
|
287
|
+
|
|
215
288
|
args = parser.parse_args()
|
|
216
289
|
|
|
217
290
|
storage = Storage.load(path=args.config)
|
koleo/storage.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import typing as t
|
|
2
|
-
from
|
|
3
|
-
from dataclasses import dataclass, asdict, field
|
|
4
|
-
from sys import platform
|
|
2
|
+
from dataclasses import asdict, dataclass, field
|
|
5
3
|
from json import dump, load
|
|
6
|
-
from os import makedirs
|
|
4
|
+
from os import makedirs
|
|
5
|
+
from os import path as ospath
|
|
6
|
+
from sys import platform
|
|
7
|
+
from time import time
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
def get_adequate_config_path():
|
|
@@ -42,7 +43,7 @@ class Storage:
|
|
|
42
43
|
else:
|
|
43
44
|
data = {}
|
|
44
45
|
storage = cls(**data)
|
|
45
|
-
storage._path =
|
|
46
|
+
storage._path = expanded
|
|
46
47
|
return storage
|
|
47
48
|
|
|
48
49
|
def get_cache(self, id: str) -> t.Any | None:
|
|
@@ -62,10 +63,9 @@ class Storage:
|
|
|
62
63
|
return item
|
|
63
64
|
|
|
64
65
|
def save(self):
|
|
65
|
-
|
|
66
|
-
dir = ospath.dirname(expanded)
|
|
66
|
+
dir = ospath.dirname(self._path)
|
|
67
67
|
if dir:
|
|
68
68
|
if not ospath.exists(dir):
|
|
69
69
|
makedirs(dir)
|
|
70
|
-
with open(
|
|
71
|
-
dump(asdict(self), f)
|
|
70
|
+
with open(self._path, "w+") as f:
|
|
71
|
+
dump(asdict(self), f, indent=True)
|
koleo/types.py
CHANGED
|
@@ -12,6 +12,7 @@ class ExtendedBaseStationInfo(BaseStationInfo):
|
|
|
12
12
|
hits: int
|
|
13
13
|
version: str # "A", "B"
|
|
14
14
|
is_group: bool
|
|
15
|
+
city: str | None
|
|
15
16
|
region: str
|
|
16
17
|
country: str
|
|
17
18
|
latitude: float
|
|
@@ -175,3 +176,9 @@ class TrainStop(t.TypedDict):
|
|
|
175
176
|
class TrainDetailResponse(t.TypedDict):
|
|
176
177
|
train: TrainDetail
|
|
177
178
|
stops: list[TrainStop]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class ConnectiontrainDetail(TrainDetail):
|
|
182
|
+
|
|
183
|
+
arrival: TimeDict | str # WTF KOLEO!!!!
|
|
184
|
+
departure: TimeDict | str # WTF KOLEO!!!!
|
koleo/utils.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
from datetime import datetime, time
|
|
1
|
+
from datetime import datetime, time, timedelta
|
|
2
2
|
|
|
3
3
|
from .types import TimeDict
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def parse_datetime(s: str):
|
|
7
|
-
now = datetime.today()
|
|
8
7
|
try:
|
|
8
|
+
now = datetime.now()
|
|
9
9
|
dt = datetime.strptime(s, "%d-%m")
|
|
10
10
|
return dt.replace(year=now.year, hour=0, minute=0)
|
|
11
11
|
except ValueError:
|
|
@@ -14,12 +14,16 @@ def parse_datetime(s: str):
|
|
|
14
14
|
return datetime.strptime(s, "%Y-%m-%d").replace(hour=0, minute=0)
|
|
15
15
|
except ValueError:
|
|
16
16
|
pass
|
|
17
|
-
|
|
17
|
+
if s[0] == "+":
|
|
18
|
+
return datetime.now().replace(hour=0, minute=0) + timedelta(days=int(s[1:]))
|
|
19
|
+
return datetime.combine(datetime.now(), datetime.strptime(s, "%H:%M").time())
|
|
18
20
|
|
|
19
21
|
|
|
20
|
-
def
|
|
22
|
+
def arr_dep_to_dt(i: TimeDict | str):
|
|
23
|
+
if isinstance(i, str):
|
|
24
|
+
return datetime.fromisoformat(i)
|
|
21
25
|
now = datetime.today()
|
|
22
|
-
return datetime.combine(now, time(
|
|
26
|
+
return datetime.combine(now, time(i["hour"], i["minute"], i["second"]))
|
|
23
27
|
|
|
24
28
|
|
|
25
29
|
TRANSLITERATIONS = {
|
|
@@ -52,8 +56,8 @@ NUMERAL_TO_ARABIC = {
|
|
|
52
56
|
"VIII": 8,
|
|
53
57
|
"IX": 9,
|
|
54
58
|
"X": 10,
|
|
55
|
-
"XI": 11,
|
|
56
|
-
"XII": 12
|
|
59
|
+
"XI": 11, # wtf poznań???
|
|
60
|
+
"XII": 12, # just to be safe
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
koleo/__init__.py,sha256=N_IkOBZCSPCCw31Hu72CFys707PziGFmXpNVl0CXAz8,47
|
|
2
|
+
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
+
koleo/api.py,sha256=4qMx7pyfX_DR830BzfzwfWnmuiRQyvvWO42KwAl8Lqo,5422
|
|
4
|
+
koleo/cli.py,sha256=raS5fkz42YY3gVJXpoExid1Dkc99vmM-hPgTvHsUZGM,12742
|
|
5
|
+
koleo/storage.py,sha256=l48A8zsP3t77nFZA23dDncoeyV_VlhJ1RvM3xjWug2Q,2001
|
|
6
|
+
koleo/types.py,sha256=n7eXJfWD9BbCY6pwhPZhrArZsCqNSnGra2-ZSYwxJ58,3916
|
|
7
|
+
koleo/utils.py,sha256=N9ceKXsxC4RrG_W2PJopSL8Dsj44rFs2rDkyzM4m4ek,1428
|
|
8
|
+
koleo_cli-0.2.137.2.dist-info/METADATA,sha256=f980X6ifdRtYmDoq6-8lHz_Quz7pm4RZUlOI66OKVKw,626
|
|
9
|
+
koleo_cli-0.2.137.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
10
|
+
koleo_cli-0.2.137.2.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
11
|
+
koleo_cli-0.2.137.2.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
12
|
+
koleo_cli-0.2.137.2.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
koleo/__init__.py,sha256=ChPpKyc4vrcgWj-Uk_ZlDw32s_7iFpE3f1FTAd6zxPY,51
|
|
2
|
-
koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
-
koleo/api.py,sha256=uzaOSD_voMRoIxKRuh-RqGKGcJDyAUh3UtOvchW-skc,5052
|
|
4
|
-
koleo/cli.py,sha256=ARSDB6bLYf0c2gSkY_A_b4BoniaMBamCfCUByZsSl5o,9365
|
|
5
|
-
koleo/storage.py,sha256=uCh6edwizAuw1z_Ti5AXvDan2pJAJBSobCVmYw096F8,2015
|
|
6
|
-
koleo/types.py,sha256=8mAsRdNh3jMJwAV5KnHVvDQAekhs0N70EVem4p_w18o,3760
|
|
7
|
-
koleo/utils.py,sha256=vywC_2q_quCdk23GPYXzm6oteCYwHcS3AVwK2pYv1NQ,1224
|
|
8
|
-
koleo_cli-0.2.137.1.dist-info/METADATA,sha256=MXri6goTJkWZs2XgcsdSm-MHie9-53nWXCleo4XVIJU,626
|
|
9
|
-
koleo_cli-0.2.137.1.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
|
10
|
-
koleo_cli-0.2.137.1.dist-info/entry_points.txt,sha256=LtCidkVDq8Zd7-fxpRbys1Xa9LTHMZwXVbdcQEscdes,41
|
|
11
|
-
koleo_cli-0.2.137.1.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
|
|
12
|
-
koleo_cli-0.2.137.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|