koleo-cli 0.2.137.16__py3-none-any.whl → 0.2.137.18__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.

@@ -0,0 +1,26 @@
1
+ koleo/__init__.py,sha256=dp6PfGcuWP50QBWhjnT-zS03l3KzzYnMJnUeYMKBayc,51
2
+ koleo/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
3
+ koleo/args.py,sha256=gncN8HA8a67U1Wpt3lc32bvPBydn0uCkSmiCZNVQRGk,10275
4
+ koleo/storage.py,sha256=pffcqpTakYp8o6dbVMkD5oF13R6L2eQR3ambU8qTRuM,4345
5
+ koleo/utils.py,sha256=OAjm90SN1BqpgNF8OTAaR9atyLNYIGy5owZ2pLP5OAM,4631
6
+ koleo/api/__init__.py,sha256=3TfO8eBJcDCDXvIFobgyvN3Sfa1kQ2U0lm7gxEAsaWQ,50
7
+ koleo/api/base.py,sha256=8wAasDQ1DBDI1PsPESmS3iUE5csIgaGT4DOX_A-hPwI,2070
8
+ koleo/api/client.py,sha256=Ru5M5ntp2vpQQI4VUaD1TCLIjNtJB4tkNCB4y766DUU,8457
9
+ koleo/api/errors.py,sha256=J9g75K9_yvnZ-7Hi521h0yGcw9NUNnTprQsIZ_mclO0,1324
10
+ koleo/api/logging.py,sha256=VhOFY6N_mofFfg9ZJ5ZnDVCzNuRilqLqrzZU9b-hpZY,1644
11
+ koleo/api/types.py,sha256=udCQeDjRvUqrUkuE_-Jidzsq_FOCjNyGd_bQWm3f9iA,10594
12
+ koleo/cli/__init__.py,sha256=50B_lMtZS27_FVrkIa2TOWMX7SozG1CPPMxbY1W9tqk,266
13
+ koleo/cli/aliases.py,sha256=is3NX5g0-ujJTmyjlFLoNnK_pwoYUVIojWNkgwXRBKk,581
14
+ koleo/cli/base.py,sha256=Rdv8FwenM0ymSHNrW9faGYI6mr65EL-n24bN5YXfLkg,4261
15
+ koleo/cli/connections.py,sha256=LJzoq3ADVUmBeqF4-h_me3pZbBHYg1sG3MaDYprwuLU,6873
16
+ koleo/cli/seats.py,sha256=hIALtopQPD-BcBGI_XpPo3ht6f_D5e16VpI7mFgN0Ao,5477
17
+ koleo/cli/station_board.py,sha256=lRGIeEKEOvUcctM6cwmqVE7Yk9m9R12gfFZahlWLQFc,3669
18
+ koleo/cli/stations.py,sha256=6L3PBWc6xssyR9eeLacuvGBJmaY7Ny3DalKy2Xq7zsA,1633
19
+ koleo/cli/train_info.py,sha256=XS_G4dsevHBPuGSpsbNTh_adSLyedame7WVe71oIe5M,7259
20
+ koleo/cli/utils.py,sha256=FzPGcJdwRwcz10mYiW63Y4zpjM9j6DzNH91UNR3MS8s,666
21
+ koleo_cli-0.2.137.18.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
22
+ koleo_cli-0.2.137.18.dist-info/METADATA,sha256=JLxhaXfSUCa7zhq12sGS8LLP94BvnW2Tc3DoFOk9NYU,4731
23
+ koleo_cli-0.2.137.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ koleo_cli-0.2.137.18.dist-info/entry_points.txt,sha256=ouWbMR_XWpEwV7zfkFKeiFLe_IMP-47kTvVahgy4PRg,42
25
+ koleo_cli-0.2.137.18.dist-info/top_level.txt,sha256=AlWdXotkRYzHpFfOBYi6xOXl1H0zq4-tqtZ2XivoWB4,6
26
+ koleo_cli-0.2.137.18.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.7.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ koleo = koleo.args:main
koleo/api.py DELETED
@@ -1,161 +0,0 @@
1
- import typing as t
2
- from datetime import datetime
3
-
4
- from requests import PreparedRequest, Response, Session
5
-
6
- from koleo.types import *
7
-
8
-
9
- class errors:
10
- class KoleoAPIException(Exception):
11
- status: int
12
- request: PreparedRequest
13
- response: Response
14
-
15
- def __init__(self, response: Response, *args: object) -> None:
16
- super().__init__(*args)
17
- self.status = response.status_code
18
- self.request = response.request
19
- self.response = response
20
-
21
- @classmethod
22
- def from_response(cls, response: Response) -> "t.Self":
23
- if response.status_code == 404:
24
- return errors.KoleoNotFound(response)
25
- elif response.status_code == 401:
26
- return errors.KoleoUnauthorized(response)
27
- elif response.status_code == 403:
28
- return errors.KoleoForbidden(response)
29
- elif response.status_code == 429:
30
- return errors.KoleoRatelimited(response)
31
- else:
32
- return cls(response)
33
-
34
- class KoleoNotFound(KoleoAPIException):
35
- pass
36
-
37
- class KoleoForbidden(KoleoAPIException):
38
- pass
39
-
40
- class KoleoUnauthorized(KoleoAPIException):
41
- pass
42
-
43
- class KoleoRatelimited(KoleoAPIException):
44
- pass
45
-
46
-
47
- class KoleoAPI:
48
- errors = errors
49
-
50
- def __init__(self) -> None:
51
- self.session = Session()
52
- self.base_url = "https://koleo.pl"
53
- self.version = 2
54
- self.base_headers = {
55
- "x-koleo-version": str(self.version),
56
- "User-Agent": "Koleo-CLI(https://pypi.org/project/koleo-cli)",
57
- }
58
-
59
- def _get(self, path, *args, **kwargs) -> Response:
60
- headers = {**self.base_headers, **kwargs.get("headers", {})}
61
- r = self.session.get(self.base_url + path, *args, headers=headers, **kwargs)
62
- if not r.ok:
63
- raise errors.KoleoAPIException.from_response(r)
64
- return r
65
-
66
- def _get_json(self, path, *args, **kwargs) -> t.Any:
67
- r = self._get(path, *args, **kwargs)
68
- res = r.json()
69
- if res is None:
70
- raise self.errors.KoleoNotFound(r)
71
- return res
72
-
73
- def _get_bytes(self, path, *args, **kwargs) -> bytes:
74
- r = self._get(path, *args, **kwargs)
75
- return r.content
76
-
77
- def get_stations(self) -> list[ExtendedStationInfo]:
78
- return self._get_json("/api/v2/main/stations")
79
-
80
- def find_station(self, query: str, language: str = "pl") -> list[ExtendedStationInfo]:
81
- # https://koleo.pl/ls?q=tere&language=pl
82
- return self._get_json("/ls", params={"q": query, "language": language})["stations"]
83
-
84
- def get_station_by_id(self, id: int) -> ExtendedBaseStationInfo:
85
- # https://koleo.pl/api/v2/main/stations/by_id/24000
86
- return self._get_json(
87
- f"/api/v2/main/stations/by_id/{id}",
88
- )
89
-
90
- def get_station_by_slug(self, slug: str) -> ExtendedBaseStationInfo:
91
- # https://koleo.pl/api/v2/main/stations/by_slug/inowroclaw
92
- return self._get_json(
93
- f"/api/v2/main/stations/by_slug/{slug}",
94
- )
95
-
96
- def get_station_info_by_slug(self, slug: str) -> StationDetails:
97
- # https://koleo.pl/api/v2/main/station_info/inowroclaw
98
- return self._get_json(
99
- f"/api/v2/main/station_info/{slug}",
100
- )
101
-
102
- def get_departures(self, station_id: int, date: datetime) -> list[TrainOnStationInfo]:
103
- # https://koleo.pl/api/v2/main/timetables/18705/2024-03-25/departures
104
- return self._get_json(
105
- f"/api/v2/main/timetables/{station_id}/{date.strftime("%Y-%m-%d")}/departures",
106
- )
107
-
108
- def get_arrivals(self, station_id: int, date: datetime) -> list[TrainOnStationInfo]:
109
- # https://koleo.pl/api/v2/main/timetables/18705/2024-03-25/arrivals
110
- return self._get_json(
111
- f"/api/v2/main/timetables/{station_id}/{date.strftime("%Y-%m-%d")}/arrivals",
112
- )
113
-
114
- def get_train_calendars(self, brand_name: str, number: int, name: str | None = None) -> TrainCalendarResponse:
115
- # https://koleo.pl/pl/train_calendars?brand=REG&nr=10417
116
- # https://koleo.pl/pl/train_calendars?brand=IC&nr=1106&name=ESPERANTO ; WHY!!!! WHY!!!!!!1
117
- params = {"brand": brand_name, "nr": number}
118
- if name:
119
- params["name"] = name.upper() # WHY!!!!!!!!!
120
- return self._get_json("/pl/train_calendars", params=params)
121
-
122
- def get_train(self, id: int) -> TrainDetailResponse:
123
- # https://koleo.pl/pl/trains/142821312
124
- return self._get_json(f"/pl/trains/{id}")
125
-
126
- def get_connections(
127
- self,
128
- start: str,
129
- end: str,
130
- brand_ids: list[int],
131
- date: datetime,
132
- direct: bool = False,
133
- purchasable: bool = False,
134
- ) -> list[ConnectionDetail]:
135
- params = {
136
- "query[date]": date.strftime("%d-%m-%Y %H:%M:%S"),
137
- "query[start_station]": start,
138
- "query[end_station]": end,
139
- "query[only_purchasable]": str(purchasable).lower(),
140
- "query[only_direct]": str(direct).lower(),
141
- "query[brand_ids][]": brand_ids,
142
- }
143
- return self._get_json("/api/v2/main/connections", params=params)["connections"]
144
-
145
- def get_brands(self) -> list[ApiBrand]:
146
- # https://koleo.pl/api/v2/main/brands
147
- return self._get_json(
148
- "/api/v2/main/brands",
149
- )
150
-
151
- def get_carriers(self) -> list[Carrier]:
152
- # https://koleo.pl/api/v2/main/carriers
153
- return self._get_json(
154
- "/api/v2/main/carriers",
155
- )
156
-
157
- def get_discounts(self) -> list[DiscountInfo]:
158
- # https://koleo.pl/api/v2/main/discounts
159
- return self._get_json(
160
- "/api/v2/main/discounts",
161
- )