arpakitlib 1.7.214__py3-none-any.whl → 1.7.215__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.
- arpakitlib/ar_arpakit_schedule_uust_api_client_util.py +46 -104
- arpakitlib/ar_http_request_util.py +20 -8
- arpakitlib/ar_schedule_uust_api_client_util.py +4 -2
- {arpakitlib-1.7.214.dist-info → arpakitlib-1.7.215.dist-info}/METADATA +1 -1
- {arpakitlib-1.7.214.dist-info → arpakitlib-1.7.215.dist-info}/RECORD +8 -8
- {arpakitlib-1.7.214.dist-info → arpakitlib-1.7.215.dist-info}/LICENSE +0 -0
- {arpakitlib-1.7.214.dist-info → arpakitlib-1.7.215.dist-info}/WHEEL +0 -0
- {arpakitlib-1.7.214.dist-info → arpakitlib-1.7.215.dist-info}/entry_points.txt +0 -0
@@ -3,21 +3,18 @@
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
5
|
import asyncio
|
6
|
-
import hashlib
|
7
|
-
import json
|
8
6
|
import logging
|
9
7
|
from datetime import timedelta, datetime, time
|
10
8
|
from typing import Any
|
11
9
|
from urllib.parse import urljoin
|
12
10
|
|
13
|
-
import aiohttp
|
14
11
|
import cachetools
|
15
|
-
from aiohttp import ClientResponse
|
12
|
+
from aiohttp import ClientResponse
|
16
13
|
from pydantic import ConfigDict, BaseModel
|
17
14
|
|
18
15
|
from arpakitlib.ar_enumeration_util import Enumeration
|
19
|
-
from arpakitlib.
|
20
|
-
from arpakitlib.
|
16
|
+
from arpakitlib.ar_http_request_util import async_make_http_request
|
17
|
+
from arpakitlib.ar_json_util import safely_transfer_obj_to_json_str
|
21
18
|
|
22
19
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
23
20
|
|
@@ -53,17 +50,20 @@ class BaseAPIModel(BaseModel):
|
|
53
50
|
|
54
51
|
class CurrentSemesterAPIModel(BaseAPIModel):
|
55
52
|
id: int
|
53
|
+
long_id: str
|
56
54
|
creation_dt: datetime
|
57
|
-
|
55
|
+
entity_type: str
|
56
|
+
actualization_dt: datetime
|
58
57
|
value: str
|
59
|
-
raw_value: str
|
60
58
|
|
61
59
|
|
62
60
|
class CurrentWeekAPIModel(BaseAPIModel):
|
63
61
|
id: int
|
62
|
+
long_id: str
|
64
63
|
creation_dt: datetime
|
65
|
-
|
66
|
-
|
64
|
+
entity_type: str
|
65
|
+
actualization_dt: datetime
|
66
|
+
value: int
|
67
67
|
|
68
68
|
|
69
69
|
class GroupAPIModel(BaseAPIModel):
|
@@ -209,91 +209,47 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
209
209
|
if self.ttl_cache is not None:
|
210
210
|
self.ttl_cache.clear()
|
211
211
|
|
212
|
-
async def _async_make_request(
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
212
|
+
async def _async_make_request(
|
213
|
+
self,
|
214
|
+
*,
|
215
|
+
method: str = "GET",
|
216
|
+
url: str,
|
217
|
+
params: dict[str, Any] | None = None,
|
218
|
+
**kwargs
|
219
|
+
) -> ClientResponse:
|
220
|
+
response = await async_make_http_request(
|
221
|
+
method=method,
|
222
|
+
url=url,
|
223
|
+
headers=self.headers,
|
224
|
+
params=params,
|
225
|
+
raise_for_status_=True,
|
226
|
+
**kwargs
|
224
227
|
)
|
228
|
+
return response
|
225
229
|
|
226
|
-
|
227
|
-
if cache_key in self.ttl_cache:
|
228
|
-
return self.ttl_cache[cache_key]
|
229
|
-
|
230
|
-
while True:
|
231
|
-
tries += 1
|
232
|
-
self._logger.info(f"{method} {url}")
|
233
|
-
try:
|
234
|
-
async with aiohttp.ClientSession() as session:
|
235
|
-
async with session.request(**kwargs) as response:
|
236
|
-
await response.read()
|
237
|
-
if self.use_cache and self.ttl_cache is not None:
|
238
|
-
self.ttl_cache[cache_key] = response
|
239
|
-
return response
|
240
|
-
except Exception as err:
|
241
|
-
self._logger.warning(f"{tries}/{max_tries} {err} {method} {url}")
|
242
|
-
if tries >= max_tries:
|
243
|
-
raise err
|
244
|
-
await async_safe_sleep(timedelta(seconds=0.1).total_seconds())
|
245
|
-
continue
|
246
|
-
|
247
|
-
async def healthcheck(self) -> bool:
|
248
|
-
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "healthcheck"))
|
249
|
-
response.raise_for_status()
|
250
|
-
json_data = await response.json()
|
251
|
-
return json_data["data"]["healthcheck"]
|
252
|
-
|
253
|
-
async def is_healthcheck_good(self) -> bool:
|
254
|
-
try:
|
255
|
-
return await self.healthcheck()
|
256
|
-
except ClientResponseError:
|
257
|
-
return False
|
258
|
-
|
259
|
-
async def auth_healthcheck(self) -> bool:
|
230
|
+
async def check_auth(self) -> dict[str, Any]:
|
260
231
|
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "check_auth"))
|
261
|
-
response.raise_for_status()
|
262
232
|
json_data = await response.json()
|
263
|
-
return json_data
|
233
|
+
return json_data
|
264
234
|
|
265
|
-
async def
|
266
|
-
try:
|
267
|
-
return await self.auth_healthcheck()
|
268
|
-
except ClientResponseError:
|
269
|
-
return False
|
270
|
-
|
271
|
-
async def get_required_current_week_value(self) -> int:
|
235
|
+
async def get_current_week(self) -> CurrentWeekAPIModel | None:
|
272
236
|
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "get_current_week"))
|
273
|
-
response.raise_for_status()
|
274
237
|
json_data = await response.json()
|
275
|
-
|
276
|
-
|
238
|
+
if json_data is None:
|
239
|
+
return None
|
240
|
+
return CurrentWeekAPIModel.model_validate(json_data)
|
277
241
|
|
278
242
|
async def get_current_semester(self) -> CurrentSemesterAPIModel | None:
|
279
243
|
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "get_current_semester"))
|
280
244
|
json_data = await response.json()
|
281
245
|
if json_data is None:
|
282
246
|
return None
|
283
|
-
|
284
|
-
return None
|
285
|
-
response.raise_for_status()
|
286
|
-
return CurrentSemesterAPIModel.from_arpakit_uust_api_data(arpakit_uust_api_data=json_data)
|
247
|
+
return CurrentSemesterAPIModel.model_validate(json_data)
|
287
248
|
|
288
|
-
async def
|
289
|
-
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "
|
249
|
+
async def get_weather_in_ufa(self) -> WeatherInUfaAPIModel:
|
250
|
+
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "get_weather_in_ufa"))
|
290
251
|
json_data = await response.json()
|
291
|
-
|
292
|
-
return None
|
293
|
-
if "error_code" in json_data and json_data["error_code"] == "CURRENT_WEEK_NOT_FOUND":
|
294
|
-
return None
|
295
|
-
response.raise_for_status()
|
296
|
-
return CurrentWeekAPIModel.from_arpakit_uust_api_data(arpakit_uust_api_data=json_data)
|
252
|
+
return WeatherInUfaAPIModel.model_validate(json_data)
|
297
253
|
|
298
254
|
async def get_log_file_content(self) -> str | None:
|
299
255
|
|
@@ -416,40 +372,26 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
416
372
|
json_data = await response.json()
|
417
373
|
return [TeacherLessonAPIModel.from_arpakit_uust_api_data(arpakit_uust_api_data=d) for d in json_data]
|
418
374
|
|
419
|
-
async def get_weather_in_ufa(self) -> WeatherInUfaAPIModel:
|
420
|
-
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "get_weather_in_ufa"))
|
421
|
-
response.raise_for_status()
|
422
|
-
json_data = await response.json()
|
423
|
-
return WeatherInUfaAPIModel.from_arpakit_uust_api_data(json_data)
|
424
|
-
|
425
375
|
|
426
376
|
def __example():
|
427
377
|
pass
|
428
378
|
|
429
379
|
|
430
380
|
async def __async_example():
|
431
|
-
client = ARPAKITScheduleUUSTAPIClient(api_key="
|
432
|
-
|
433
|
-
healthcheck = await client.healthcheck()
|
434
|
-
print(f"Healthcheck: {healthcheck}")
|
435
|
-
|
436
|
-
auth_healthcheck = await client.auth_healthcheck()
|
437
|
-
print(f"Auth Healthcheck: {auth_healthcheck}")
|
438
|
-
|
439
|
-
current_week = await client.get_current_week()
|
440
|
-
print(f"Текущая неделя: {current_week.simple_json() if current_week else 'Не найдено'}")
|
381
|
+
client = ARPAKITScheduleUUSTAPIClient(api_key="viewer", use_cache=True)
|
441
382
|
|
442
|
-
|
443
|
-
print(
|
383
|
+
print(f"check_auth")
|
384
|
+
print(safely_transfer_obj_to_json_str(await client.check_auth()))
|
385
|
+
print()
|
444
386
|
|
445
|
-
|
446
|
-
print(
|
387
|
+
print(f"get_weather_in_ufa")
|
388
|
+
print(safely_transfer_obj_to_json_str((await client.get_weather_in_ufa()).model_dump()))
|
447
389
|
|
448
|
-
|
449
|
-
print(
|
390
|
+
print(f"get_current_week")
|
391
|
+
print(safely_transfer_obj_to_json_str((await client.get_current_week()).model_dump()))
|
450
392
|
|
451
|
-
|
452
|
-
print(
|
393
|
+
print(f"get_current_semester")
|
394
|
+
print(safely_transfer_obj_to_json_str((await client.get_current_semester()).model_dump()))
|
453
395
|
|
454
396
|
|
455
397
|
if __name__ == '__main__':
|
@@ -26,6 +26,7 @@ def sync_make_http_request(
|
|
26
26
|
max_tries_: int = 9,
|
27
27
|
proxy_url_: str | None = None,
|
28
28
|
raise_for_status_: bool = False,
|
29
|
+
not_raise_for_statuses: list[int] | None = None,
|
29
30
|
timeout_: timedelta | float = timedelta(seconds=15).total_seconds(),
|
30
31
|
enable_logging_: bool = False,
|
31
32
|
**kwargs
|
@@ -53,21 +54,25 @@ def sync_make_http_request(
|
|
53
54
|
kwargs["allow_redirects"] = True
|
54
55
|
|
55
56
|
if enable_logging_:
|
56
|
-
_logger.info(f"
|
57
|
+
_logger.info(f"try http {method} {url} {params}")
|
57
58
|
|
58
59
|
while True:
|
59
60
|
tries_counter += 1
|
60
61
|
try:
|
61
62
|
response = requests.request(**kwargs)
|
62
63
|
if raise_for_status_:
|
63
|
-
response.
|
64
|
+
if not_raise_for_statuses and response.status_code in not_raise_for_statuses:
|
65
|
+
if enable_logging_:
|
66
|
+
_logger.info(f"ignored status {response.status_code} for http {method} {url} {params}")
|
67
|
+
else:
|
68
|
+
response.raise_for_status()
|
64
69
|
if enable_logging_:
|
65
|
-
_logger.info(f"
|
70
|
+
_logger.info(f"good try http {method} {url} {params}")
|
66
71
|
return response
|
67
72
|
except BaseException as exception:
|
68
73
|
if enable_logging_:
|
69
74
|
_logger.warning(
|
70
|
-
f"{tries_counter}/{max_tries_}.
|
75
|
+
f"{tries_counter}/{max_tries_}. retry {method} {url} {params}, exception={exception}"
|
71
76
|
)
|
72
77
|
if tries_counter >= max_tries_:
|
73
78
|
raise exception
|
@@ -84,6 +89,7 @@ async def async_make_http_request(
|
|
84
89
|
max_tries_: int = 9,
|
85
90
|
proxy_url_: str | None = None,
|
86
91
|
raise_for_status_: bool = False,
|
92
|
+
not_raise_for_statuses: list[int] | None = None,
|
87
93
|
timeout_: timedelta | None = timedelta(seconds=15),
|
88
94
|
enable_logging_: bool = False,
|
89
95
|
**kwargs
|
@@ -106,7 +112,7 @@ async def async_make_http_request(
|
|
106
112
|
proxy_connector = ProxyConnector.from_url(proxy_url_)
|
107
113
|
|
108
114
|
if enable_logging_:
|
109
|
-
_logger.info(f"
|
115
|
+
_logger.info(f"try http {method} {url} {params}")
|
110
116
|
|
111
117
|
while True:
|
112
118
|
tries_counter += 1
|
@@ -114,15 +120,21 @@ async def async_make_http_request(
|
|
114
120
|
async with aiohttp.ClientSession(connector=proxy_connector) as session:
|
115
121
|
async with session.request(**kwargs) as response:
|
116
122
|
if raise_for_status_:
|
117
|
-
response.
|
123
|
+
if not_raise_for_statuses and response.status in not_raise_for_statuses:
|
124
|
+
if enable_logging_:
|
125
|
+
_logger.info(
|
126
|
+
f"ignored status {response.status} for http {method} {url} {params}"
|
127
|
+
)
|
128
|
+
else:
|
129
|
+
response.raise_for_status()
|
118
130
|
await response.read()
|
119
131
|
if enable_logging_:
|
120
|
-
_logger.info(f"
|
132
|
+
_logger.info(f"good try http {method} {url} {params}")
|
121
133
|
return response
|
122
134
|
except BaseException as exception:
|
123
135
|
if enable_logging_:
|
124
136
|
_logger.warning(
|
125
|
-
f"{tries_counter}/{max_tries_}.
|
137
|
+
f"{tries_counter}/{max_tries_}. retry http {method} {url} {params}, exception={exception}"
|
126
138
|
)
|
127
139
|
if tries_counter >= max_tries_:
|
128
140
|
raise exception
|
@@ -77,7 +77,8 @@ class ScheduleUUSTAPIClient:
|
|
77
77
|
*,
|
78
78
|
method: str = "GET",
|
79
79
|
url: str,
|
80
|
-
params: dict[str, Any] | None = None
|
80
|
+
params: dict[str, Any] | None = None,
|
81
|
+
**kwargs
|
81
82
|
) -> ClientResponse:
|
82
83
|
response = await async_make_http_request(
|
83
84
|
method=method,
|
@@ -85,7 +86,8 @@ class ScheduleUUSTAPIClient:
|
|
85
86
|
headers=self.headers,
|
86
87
|
params=combine_dicts(params, self.auth_params()),
|
87
88
|
proxy_url_=self.api_proxy_url,
|
88
|
-
raise_for_status_=True
|
89
|
+
raise_for_status_=True,
|
90
|
+
**kwargs
|
89
91
|
)
|
90
92
|
json_data = await response.json()
|
91
93
|
if "error" in json_data.keys():
|
@@ -120,7 +120,7 @@ arpakitlib/ar_aiogram_util.py,sha256=5JPCDZpdBGTE-EIWPRez9amCZAX7XemFIVu5YrQK7Pw
|
|
120
120
|
arpakitlib/ar_api_key_util.py,sha256=E84JlJXiDHtxLQmV8BNHvqNKu_G8-Dox0XxknYJQ37Q,422
|
121
121
|
arpakitlib/ar_arpakit_lib_module_util.py,sha256=UEPU8wk29R_bBP_RENnhXYzNbj_RF9FWjowrj_yxWLA,5931
|
122
122
|
arpakitlib/ar_arpakit_project_template_util.py,sha256=c7yc8w2IvZGH5hH8eOpL7JuD005hUxZ0GVDcSkJF5iI,3705
|
123
|
-
arpakitlib/ar_arpakit_schedule_uust_api_client_util.py,sha256=
|
123
|
+
arpakitlib/ar_arpakit_schedule_uust_api_client_util.py,sha256=z4-wf8r35Zx3XwHrmZ9BFwKj2hssTg3oP2ql8aLlkpI,12872
|
124
124
|
arpakitlib/ar_arpakitlib_cli_util.py,sha256=8lhEDxnwMSRX2PGV2xQtQru1AYKSA92SVolol5u7iBk,3154
|
125
125
|
arpakitlib/ar_base64_util.py,sha256=aZkg2cZTuAaP2IWeG_LXJ6RO7qhyskVwec-Lks0iM-k,676
|
126
126
|
arpakitlib/ar_base_worker_util.py,sha256=Qm_C7PFH5W-LPu1AGX1zp29zbqZ04i71Su1U-eeQBkA,5674
|
@@ -157,7 +157,7 @@ arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyj
|
|
157
157
|
arpakitlib/ar_file_util.py,sha256=GUdJYm1tUZnYpY-SIPRHAZBHGra8NKy1eYEI0D5AfhY,489
|
158
158
|
arpakitlib/ar_func_util.py,sha256=bCuWbSMoFXBaMNhb89sevj2oaXRk4Jk6Qjot8OXMDT4,1319
|
159
159
|
arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
|
160
|
-
arpakitlib/ar_http_request_util.py,sha256=
|
160
|
+
arpakitlib/ar_http_request_util.py,sha256=tvYtLiTGxJ0tsoQm4SqBsPmlUn2X0qQPDeetVEIZ7Lk,5078
|
161
161
|
arpakitlib/ar_ip_util.py,sha256=aEAa1Hvobh9DWX7cmBAPLqnXSTiKe2hRk-WJaiKMaI8,1009
|
162
162
|
arpakitlib/ar_json_db_util.py,sha256=CEyhIU4WuNmX5mqwBVYxUKSdpFelXvWmf_tJ1fuxMSE,7187
|
163
163
|
arpakitlib/ar_json_util.py,sha256=wJOsN8N7Rs7r8cTgMDXrmFa1GOkcD-LghqFEYXc8zGA,1083
|
@@ -172,7 +172,7 @@ arpakitlib/ar_operation_execution_util.py,sha256=uWLDJWYbfsYItUQ48qOSWy4qxCTCFMj
|
|
172
172
|
arpakitlib/ar_parse_command.py,sha256=-s61xcATIsfw1eV_iD3xi-grsitbGzSDoAFc5V0OFy4,3447
|
173
173
|
arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJAdo,945
|
174
174
|
arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
|
175
|
-
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=
|
175
|
+
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=93d-bc3S0PddqV65lSvmApcSoDV0gqxPVgIaB7zKXfY,6899
|
176
176
|
arpakitlib/ar_settings_util.py,sha256=rnoTqbRuhiq7294D4crD5kbnU8-gNWJbwGU_Ls2gJoU,2199
|
177
177
|
arpakitlib/ar_sleep_util.py,sha256=OaLtRaJQWMkGjfj_mW1RB2P4RaSWsAIH8LUoXqsH0zM,1061
|
178
178
|
arpakitlib/ar_sqladmin_util.py,sha256=6Nv9VQssk9PB0piyuss__soYKdjVhdbIeXIv4AgUxmQ,2660
|
@@ -183,8 +183,8 @@ arpakitlib/ar_str_util.py,sha256=yU5gOwNXUQaH5b_tM5t6fXUn9oUcv5EQbVnq2wXXIpQ,337
|
|
183
183
|
arpakitlib/ar_type_util.py,sha256=9C3ErtUVs0tAUqtK-foFzjJOykfBOntfCz2IogDOgfA,4134
|
184
184
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=sh4fcUkAkdOetFn9JYoTvjcSXP-M1wU04KEY-ECLfLg,5137
|
185
185
|
arpakitlib/ar_zabbix_api_client_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
|
186
|
-
arpakitlib-1.7.
|
187
|
-
arpakitlib-1.7.
|
188
|
-
arpakitlib-1.7.
|
189
|
-
arpakitlib-1.7.
|
190
|
-
arpakitlib-1.7.
|
186
|
+
arpakitlib-1.7.215.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
187
|
+
arpakitlib-1.7.215.dist-info/METADATA,sha256=bsO-2VQN0dR4NGW3mNLbKZXXQu2ORXQEn87jXq49KZk,3176
|
188
|
+
arpakitlib-1.7.215.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
189
|
+
arpakitlib-1.7.215.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
190
|
+
arpakitlib-1.7.215.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|