arpakitlib 1.7.229__py3-none-any.whl → 1.7.232__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 +127 -93
- arpakitlib/ar_arpakit_schedule_uust_site_util.py +68 -0
- arpakitlib/ar_dream_ai_api_client_util.py +3 -2
- arpakitlib/ar_fastapi_util.py +45 -6
- arpakitlib/ar_http_request_util.py +9 -9
- arpakitlib/ar_logging_util.py +2 -2
- arpakitlib/ar_retry_func_util.py +5 -0
- arpakitlib/ar_schedule_uust_api_client_util.py +3 -1
- arpakitlib/ar_yookassa_api_client_util.py +6 -0
- {arpakitlib-1.7.229.dist-info → arpakitlib-1.7.232.dist-info}/METADATA +1 -1
- {arpakitlib-1.7.229.dist-info → arpakitlib-1.7.232.dist-info}/RECORD +14 -13
- {arpakitlib-1.7.229.dist-info → arpakitlib-1.7.232.dist-info}/LICENSE +0 -0
- {arpakitlib-1.7.229.dist-info → arpakitlib-1.7.232.dist-info}/WHEEL +0 -0
- {arpakitlib-1.7.229.dist-info → arpakitlib-1.7.232.dist-info}/entry_points.txt +0 -0
@@ -3,8 +3,8 @@
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
5
|
import asyncio
|
6
|
+
import datetime as dt
|
6
7
|
import logging
|
7
|
-
from datetime import timedelta, datetime, time
|
8
8
|
from typing import Any
|
9
9
|
from urllib.parse import urljoin
|
10
10
|
|
@@ -45,33 +45,33 @@ class Months(Enumeration):
|
|
45
45
|
|
46
46
|
|
47
47
|
class BaseAPIModel(BaseModel):
|
48
|
-
model_config = ConfigDict(extra="
|
48
|
+
model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True, from_attributes=True)
|
49
49
|
|
50
50
|
|
51
51
|
class CurrentSemesterAPIModel(BaseAPIModel):
|
52
52
|
id: int
|
53
53
|
long_id: str
|
54
|
-
creation_dt: datetime
|
54
|
+
creation_dt: dt.datetime
|
55
55
|
entity_type: str
|
56
|
-
actualization_dt: datetime
|
56
|
+
actualization_dt: dt.datetime
|
57
57
|
value: str
|
58
58
|
|
59
59
|
|
60
60
|
class CurrentWeekAPIModel(BaseAPIModel):
|
61
61
|
id: int
|
62
62
|
long_id: str
|
63
|
-
creation_dt: datetime
|
63
|
+
creation_dt: dt.datetime
|
64
64
|
entity_type: str
|
65
|
-
actualization_dt: datetime
|
65
|
+
actualization_dt: dt.datetime
|
66
66
|
value: int
|
67
67
|
|
68
68
|
|
69
69
|
class GroupAPIModel(BaseAPIModel):
|
70
70
|
id: int
|
71
71
|
long_id: str
|
72
|
-
creation_dt: datetime
|
72
|
+
creation_dt: dt.datetime
|
73
73
|
entity_type: str
|
74
|
-
actualization_dt: datetime
|
74
|
+
actualization_dt: dt.datetime
|
75
75
|
uust_api_id: int
|
76
76
|
title: str
|
77
77
|
faculty: str | None
|
@@ -83,9 +83,9 @@ class GroupAPIModel(BaseAPIModel):
|
|
83
83
|
class TeacherAPIModel(BaseAPIModel):
|
84
84
|
id: int
|
85
85
|
long_id: str
|
86
|
-
creation_dt: datetime
|
86
|
+
creation_dt: dt.datetime
|
87
87
|
entity_type: str
|
88
|
-
actualization_dt: datetime
|
88
|
+
actualization_dt: dt.datetime
|
89
89
|
uust_api_id: int
|
90
90
|
name: str | None
|
91
91
|
surname: str | None
|
@@ -103,9 +103,9 @@ class TeacherAPIModel(BaseAPIModel):
|
|
103
103
|
class GroupLessonAPIModel(BaseAPIModel):
|
104
104
|
id: int
|
105
105
|
long_id: str
|
106
|
-
creation_dt: datetime
|
106
|
+
creation_dt: dt.datetime
|
107
107
|
entity_type: str
|
108
|
-
actualization_dt: datetime
|
108
|
+
actualization_dt: dt.datetime
|
109
109
|
uust_api_id: int
|
110
110
|
type: str
|
111
111
|
title: str
|
@@ -113,8 +113,8 @@ class GroupLessonAPIModel(BaseAPIModel):
|
|
113
113
|
weekday: int
|
114
114
|
comment: str | None
|
115
115
|
time_title: str | None
|
116
|
-
time_start: time | None
|
117
|
-
time_end: time | None
|
116
|
+
time_start: dt.time | None
|
117
|
+
time_end: dt.time | None
|
118
118
|
numbers: list[int]
|
119
119
|
location: str | None
|
120
120
|
teacher_uust_api_id: int | None
|
@@ -141,9 +141,9 @@ class GroupLessonAPIModel(BaseAPIModel):
|
|
141
141
|
class TeacherLessonAPIModel(BaseAPIModel):
|
142
142
|
id: int
|
143
143
|
long_id: str
|
144
|
-
creation_dt: datetime
|
144
|
+
creation_dt: dt.datetime
|
145
145
|
entity_type: str
|
146
|
-
actualization_dt: datetime
|
146
|
+
actualization_dt: dt.datetime
|
147
147
|
uust_api_id: int
|
148
148
|
type: str
|
149
149
|
title: str
|
@@ -151,8 +151,8 @@ class TeacherLessonAPIModel(BaseAPIModel):
|
|
151
151
|
weekday: int
|
152
152
|
comment: str | None
|
153
153
|
time_title: str | None
|
154
|
-
time_start: time | None
|
155
|
-
time_end: time | None
|
154
|
+
time_start: dt.time | None
|
155
|
+
time_end: dt.time | None
|
156
156
|
numbers: list[int]
|
157
157
|
location: str | None
|
158
158
|
group_uust_api_ids: list[int]
|
@@ -181,13 +181,25 @@ class WeatherInUfaAPIModel(BaseAPIModel):
|
|
181
181
|
temperature_feels_like: float
|
182
182
|
description: str
|
183
183
|
wind_speed: float
|
184
|
-
sunrise_dt: datetime
|
185
|
-
sunset_dt: datetime
|
184
|
+
sunrise_dt: dt.datetime
|
185
|
+
sunset_dt: dt.datetime
|
186
186
|
has_rain: bool
|
187
187
|
has_snow: bool
|
188
188
|
data: dict
|
189
189
|
|
190
190
|
|
191
|
+
class DatetimeAPIModel(BaseAPIModel):
|
192
|
+
date: dt.date
|
193
|
+
datetime: dt.datetime | None = None
|
194
|
+
year: int
|
195
|
+
month: int
|
196
|
+
day: int
|
197
|
+
hour: int | None = None
|
198
|
+
minute: int | None = None
|
199
|
+
second: int | None = None
|
200
|
+
microsecond: int | None = None
|
201
|
+
|
202
|
+
|
191
203
|
class ARPAKITScheduleUUSTAPIClient:
|
192
204
|
def __init__(
|
193
205
|
self,
|
@@ -195,7 +207,7 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
195
207
|
base_url: str = "https://api.schedule-uust.arpakit.com/api/v1",
|
196
208
|
api_key: str | None = "viewer",
|
197
209
|
use_cache: bool = False,
|
198
|
-
cache_ttl: timedelta | None = timedelta(minutes=10)
|
210
|
+
cache_ttl: dt.timedelta | None = dt.timedelta(minutes=10)
|
199
211
|
):
|
200
212
|
self._logger = logging.getLogger(__name__)
|
201
213
|
self.api_key = api_key
|
@@ -236,7 +248,9 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
236
248
|
return response
|
237
249
|
|
238
250
|
async def check_auth(self) -> dict[str, Any]:
|
239
|
-
response = await self._async_make_http_request(
|
251
|
+
response = await self._async_make_http_request(
|
252
|
+
method="GET", url=urljoin(self.base_url, "check_auth")
|
253
|
+
)
|
240
254
|
json_data = await response.json()
|
241
255
|
return json_data
|
242
256
|
|
@@ -265,13 +279,24 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
265
279
|
json_data = await response.json()
|
266
280
|
return WeatherInUfaAPIModel.model_validate(json_data)
|
267
281
|
|
282
|
+
async def get_now_datetime_in_ufa(self) -> DatetimeAPIModel:
|
283
|
+
response = await self._async_make_http_request(
|
284
|
+
method="GET", url=urljoin(self.base_url, "get_now_datetime_in_ufa")
|
285
|
+
)
|
286
|
+
json_data = await response.json()
|
287
|
+
return DatetimeAPIModel.model_validate(json_data)
|
288
|
+
|
268
289
|
async def get_log_file_content(self) -> str | None:
|
269
|
-
response = await self._async_make_http_request(
|
290
|
+
response = await self._async_make_http_request(
|
291
|
+
method="GET", url=urljoin(self.base_url, "get_log_file")
|
292
|
+
)
|
270
293
|
text_data = await response.text()
|
271
294
|
return text_data
|
272
295
|
|
273
296
|
async def get_groups(self) -> list[GroupAPIModel]:
|
274
|
-
response = await self._async_make_http_request(
|
297
|
+
response = await self._async_make_http_request(
|
298
|
+
method="GET", url=urljoin(self.base_url, "get_groups")
|
299
|
+
)
|
275
300
|
json_data = await response.json()
|
276
301
|
return [GroupAPIModel.model_validate(d) for d in json_data]
|
277
302
|
|
@@ -283,8 +308,8 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
283
308
|
params["filter_id"] = filter_id
|
284
309
|
if filter_uust_api_id is not None:
|
285
310
|
params["filter_uust_api_id"] = filter_uust_api_id
|
286
|
-
response = await self._async_make_http_request(
|
287
|
-
|
311
|
+
response = await self._async_make_http_request(
|
312
|
+
method="GET", url=urljoin(self.base_url, "get_group"), params=params)
|
288
313
|
json_data = await response.json()
|
289
314
|
if json_data is None:
|
290
315
|
return None
|
@@ -293,13 +318,16 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
293
318
|
async def find_groups(
|
294
319
|
self, *, q: str
|
295
320
|
) -> list[GroupAPIModel]:
|
296
|
-
response = await self._async_make_http_request(
|
297
|
-
|
321
|
+
response = await self._async_make_http_request(
|
322
|
+
method="GET", url=urljoin(self.base_url, "find_groups"), params={"q": q.strip()}
|
323
|
+
)
|
298
324
|
json_data = await response.json()
|
299
325
|
return [GroupAPIModel.model_validate(d) for d in json_data]
|
300
326
|
|
301
327
|
async def get_teachers(self) -> list[TeacherAPIModel]:
|
302
|
-
response = await self._async_make_http_request(
|
328
|
+
response = await self._async_make_http_request(
|
329
|
+
method="GET", url=urljoin(self.base_url, "get_teachers")
|
330
|
+
)
|
303
331
|
json_data = await response.json()
|
304
332
|
return [TeacherAPIModel.model_validate(d) for d in json_data]
|
305
333
|
|
@@ -311,8 +339,9 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
311
339
|
params["filter_id"] = filter_id
|
312
340
|
if filter_uust_api_id is not None:
|
313
341
|
params["filter_uust_api_id"] = filter_uust_api_id
|
314
|
-
response = await self._async_make_http_request(
|
315
|
-
|
342
|
+
response = await self._async_make_http_request(
|
343
|
+
method="GET", url=urljoin(self.base_url, "get_teacher"), params=params
|
344
|
+
)
|
316
345
|
json_data = await response.json()
|
317
346
|
if json_data is None:
|
318
347
|
return None
|
@@ -321,24 +350,26 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
321
350
|
async def find_teachers(
|
322
351
|
self, *, q: str
|
323
352
|
) -> list[TeacherAPIModel]:
|
324
|
-
response = await self._async_make_http_request(
|
325
|
-
|
353
|
+
response = await self._async_make_http_request(
|
354
|
+
method="GET", url=urljoin(self.base_url, "find_teachers"), params={"q": q.strip()}
|
355
|
+
)
|
326
356
|
json_data = await response.json()
|
327
357
|
return [TeacherAPIModel.model_validate(d) for d in json_data]
|
328
358
|
|
329
359
|
async def find_any(
|
330
360
|
self, *, q: str
|
331
361
|
) -> list[TeacherAPIModel | GroupLessonAPIModel]:
|
332
|
-
response = await self._async_make_http_request(
|
333
|
-
|
362
|
+
response = await self._async_make_http_request(
|
363
|
+
method="GET", url=urljoin(self.base_url, "find_any"), params={"q": q.strip()}
|
364
|
+
)
|
334
365
|
json_data = await response.json()
|
335
366
|
|
336
367
|
results = []
|
337
|
-
for
|
338
|
-
if
|
339
|
-
results.append(GroupAPIModel.model_validate(
|
340
|
-
elif
|
341
|
-
results.append(TeacherAPIModel.model_validate(
|
368
|
+
for d in json_data:
|
369
|
+
if d["entity_type"] == "group":
|
370
|
+
results.append(GroupAPIModel.model_validate(d))
|
371
|
+
elif d["entity_type"] == "teacher":
|
372
|
+
results.append(TeacherAPIModel.model_validate(d))
|
342
373
|
else:
|
343
374
|
pass
|
344
375
|
return results
|
@@ -391,59 +422,62 @@ async def __async_example():
|
|
391
422
|
print(f"get_weather_in_ufa")
|
392
423
|
print(safely_transfer_obj_to_json_str((await client.get_weather_in_ufa()).model_dump()))
|
393
424
|
|
394
|
-
print(f"
|
395
|
-
print(safely_transfer_obj_to_json_str((await client.
|
396
|
-
|
397
|
-
print(f"
|
398
|
-
print(safely_transfer_obj_to_json_str((await client.
|
399
|
-
|
400
|
-
#
|
401
|
-
print(
|
402
|
-
|
403
|
-
|
404
|
-
print(f"
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
print(
|
413
|
-
|
414
|
-
#
|
415
|
-
print(
|
416
|
-
|
417
|
-
|
418
|
-
print(f"
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
print(
|
427
|
-
|
428
|
-
#
|
429
|
-
print(
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
#
|
437
|
-
print(
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
#
|
445
|
-
print(
|
446
|
-
|
425
|
+
print(f"get_now_datetime_in_ufa")
|
426
|
+
print(safely_transfer_obj_to_json_str((await client.get_now_datetime_in_ufa()).model_dump()))
|
427
|
+
|
428
|
+
# print(f"get_current_week")
|
429
|
+
# print(safely_transfer_obj_to_json_str((await client.get_current_week()).model_dump()))
|
430
|
+
#
|
431
|
+
# print(f"get_current_semester")
|
432
|
+
# print(safely_transfer_obj_to_json_str((await client.get_current_semester()).model_dump()))
|
433
|
+
#
|
434
|
+
# # Group
|
435
|
+
# print(f"get_groups")
|
436
|
+
# print(safely_transfer_obj_to_json_str((await client.get_groups())))
|
437
|
+
#
|
438
|
+
# print(f"get_group")
|
439
|
+
# if await client.get_group(filter_id=25285, filter_uust_api_id=6674):
|
440
|
+
# print(safely_transfer_obj_to_json_str(
|
441
|
+
# (await client.get_group(filter_id=25285, filter_uust_api_id=6674)).model_dump()))
|
442
|
+
# else:
|
443
|
+
# print("Group is none")
|
444
|
+
#
|
445
|
+
# print(f"find_groups")
|
446
|
+
# print(safely_transfer_obj_to_json_str((await client.find_groups(q="ПИ-427Б"))))
|
447
|
+
#
|
448
|
+
# # Teacher
|
449
|
+
# print(f"get_teachers")
|
450
|
+
# print(safely_transfer_obj_to_json_str((await client.get_teachers())))
|
451
|
+
#
|
452
|
+
# print(f"get_teacher")
|
453
|
+
# if await client.get_teacher(filter_id=16975, filter_uust_api_id=112978):
|
454
|
+
# print(safely_transfer_obj_to_json_str(
|
455
|
+
# (await client.get_teacher(filter_id=16975, filter_uust_api_id=112978)).model_dump()))
|
456
|
+
# else:
|
457
|
+
# print("Teacher is none")
|
458
|
+
#
|
459
|
+
# print(f"find_teachers")
|
460
|
+
# print(safely_transfer_obj_to_json_str((await client.find_teachers(q="Казанцев"))))
|
461
|
+
#
|
462
|
+
# # Group Lesson
|
463
|
+
# print(f"get_group_lessons")
|
464
|
+
# if await client.get_group_lessons(filter_group_id=25285, filter_group_uust_api_id=6674):
|
465
|
+
# print(safely_transfer_obj_to_json_str((await client.get_group_lessons(filter_group_id=25285,
|
466
|
+
# filter_group_uust_api_id=6674))))
|
467
|
+
# else:
|
468
|
+
# print("Group lessons is none")
|
469
|
+
#
|
470
|
+
# # Teacher Lesson
|
471
|
+
# print(f"get_teacher_lessons")
|
472
|
+
# if await client.get_teacher_lessons(filter_teacher_id=16975, filter_teacher_uust_api_id=112978):
|
473
|
+
# print(safely_transfer_obj_to_json_str((await client.get_teacher_lessons(filter_teacher_id=16975,
|
474
|
+
# filter_teacher_uust_api_id=112978))))
|
475
|
+
# else:
|
476
|
+
# print("Teacher lessons is none")
|
477
|
+
#
|
478
|
+
# # Find Any
|
479
|
+
# print(f"find_any")
|
480
|
+
# print(safely_transfer_obj_to_json_str((await client.find_any(q="ПИ"))))
|
447
481
|
|
448
482
|
|
449
483
|
if __name__ == '__main__':
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# arpakit
|
2
|
+
|
3
|
+
from urllib.parse import urlencode, urljoin
|
4
|
+
|
5
|
+
from arpakitlib.ar_type_util import raise_for_type
|
6
|
+
|
7
|
+
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
8
|
+
|
9
|
+
|
10
|
+
def generate_arpakit_schedule_uust_site_url(
|
11
|
+
*,
|
12
|
+
base_url: str = "https://schedule-uust.arpakit.com",
|
13
|
+
entity_type: str | None = None,
|
14
|
+
uust_api_id: int | None = None,
|
15
|
+
session: bool | None = None,
|
16
|
+
week: int | None = None,
|
17
|
+
theme: str | None = None
|
18
|
+
) -> str:
|
19
|
+
raise_for_type(base_url, str)
|
20
|
+
|
21
|
+
params = {}
|
22
|
+
|
23
|
+
if entity_type is not None: # group/teacher
|
24
|
+
raise_for_type(entity_type, str)
|
25
|
+
params["entity_type"] = entity_type
|
26
|
+
|
27
|
+
if uust_api_id is not None: # uust_api_id of group/teacher
|
28
|
+
raise_for_type(uust_api_id, int)
|
29
|
+
params["uust_api_id"] = uust_api_id
|
30
|
+
|
31
|
+
if session is not None: # true/false
|
32
|
+
raise_for_type(session, bool)
|
33
|
+
if session:
|
34
|
+
params["session"] = "true"
|
35
|
+
else:
|
36
|
+
params["session"] = "false"
|
37
|
+
|
38
|
+
if week is not None:
|
39
|
+
raise_for_type(week, int)
|
40
|
+
params["week"] = week
|
41
|
+
|
42
|
+
if theme is not None: # dark/light
|
43
|
+
raise_for_type(theme, str)
|
44
|
+
params["theme"] = theme
|
45
|
+
|
46
|
+
if params:
|
47
|
+
res = urljoin(base_url, f"schedule?{urlencode(params)}")
|
48
|
+
else:
|
49
|
+
res = base_url
|
50
|
+
|
51
|
+
return res
|
52
|
+
|
53
|
+
|
54
|
+
def __example():
|
55
|
+
base_url = "https://schedule-uust.arpakit.com"
|
56
|
+
url = generate_arpakit_schedule_uust_site_url(
|
57
|
+
base_url=base_url,
|
58
|
+
entity_type="group",
|
59
|
+
uust_api_id=6662,
|
60
|
+
session=True,
|
61
|
+
week=23,
|
62
|
+
theme="dark"
|
63
|
+
)
|
64
|
+
print(url)
|
65
|
+
|
66
|
+
|
67
|
+
if __name__ == '__main__':
|
68
|
+
__example()
|
@@ -15,7 +15,7 @@ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
|
15
15
|
|
16
16
|
|
17
17
|
class BaseAPIModel(BaseModel):
|
18
|
-
model_config = ConfigDict(extra="
|
18
|
+
model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True, from_attributes=True)
|
19
19
|
|
20
20
|
|
21
21
|
class GenerateImageFromNumberResApiModel(BaseAPIModel):
|
@@ -76,7 +76,8 @@ class DREAMAIAPIClient:
|
|
76
76
|
|
77
77
|
async def generate_image_from_number(self, *, number: int) -> GenerateImageFromNumberResApiModel:
|
78
78
|
response = await self._async_make_http_request(
|
79
|
-
method="GET",
|
79
|
+
method="GET",
|
80
|
+
url=urljoin(self.base_url, "generate_image_from_number"),
|
80
81
|
params={"number": number}
|
81
82
|
)
|
82
83
|
json_data = await response.json()
|
arpakitlib/ar_fastapi_util.py
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
5
|
import asyncio
|
6
|
+
import datetime as dt
|
6
7
|
import logging
|
7
8
|
import os.path
|
8
9
|
import pathlib
|
9
10
|
import traceback
|
10
11
|
from contextlib import suppress
|
11
|
-
from datetime import datetime
|
12
12
|
from typing import Any, Callable
|
13
13
|
|
14
14
|
import fastapi.exceptions
|
@@ -65,7 +65,7 @@ class BaseSO(BaseSchema):
|
|
65
65
|
class SimpleSO(BaseSO):
|
66
66
|
id: int
|
67
67
|
long_id: str
|
68
|
-
creation_dt: datetime
|
68
|
+
creation_dt: dt.datetime
|
69
69
|
|
70
70
|
|
71
71
|
class BaseAPIErrorCodes(Enumeration):
|
@@ -91,6 +91,41 @@ class RawDataSO(BaseSO):
|
|
91
91
|
data: dict[str, Any] = {}
|
92
92
|
|
93
93
|
|
94
|
+
class DatetimeSO(BaseSO):
|
95
|
+
date: dt.date
|
96
|
+
datetime: dt.datetime | None = None
|
97
|
+
year: int
|
98
|
+
month: int
|
99
|
+
day: int
|
100
|
+
hour: int | None = None
|
101
|
+
minute: int | None = None
|
102
|
+
second: int | None = None
|
103
|
+
microsecond: int | None = None
|
104
|
+
|
105
|
+
@classmethod
|
106
|
+
def from_datetime(cls, datetime_: dt.datetime):
|
107
|
+
return cls(
|
108
|
+
date=datetime_.date(),
|
109
|
+
datetime=datetime_,
|
110
|
+
year=datetime_.year,
|
111
|
+
month=datetime_.month,
|
112
|
+
day=datetime_.day,
|
113
|
+
hour=datetime_.hour,
|
114
|
+
minute=datetime_.minute,
|
115
|
+
second=datetime_.second,
|
116
|
+
microsecond=datetime_.microsecond
|
117
|
+
)
|
118
|
+
|
119
|
+
@classmethod
|
120
|
+
def from_date(cls, date_: dt.date):
|
121
|
+
return cls(
|
122
|
+
date=date_,
|
123
|
+
year=date_.year,
|
124
|
+
month=date_.month,
|
125
|
+
day=date_.day
|
126
|
+
)
|
127
|
+
|
128
|
+
|
94
129
|
class StoryLogSO(SimpleSO):
|
95
130
|
level: str
|
96
131
|
title: str | None
|
@@ -102,8 +137,8 @@ class StoryLogSO(SimpleSO):
|
|
102
137
|
|
103
138
|
|
104
139
|
class OperationSO(SimpleSO):
|
105
|
-
execution_start_dt: datetime | None
|
106
|
-
execution_finish_dt: datetime | None
|
140
|
+
execution_start_dt: dt.datetime | None
|
141
|
+
execution_finish_dt: dt.datetime | None
|
107
142
|
status: str
|
108
143
|
type: str
|
109
144
|
input_data: dict[str, Any]
|
@@ -388,6 +423,10 @@ class HealthcheckSO(BaseSO):
|
|
388
423
|
is_ok: bool = True
|
389
424
|
|
390
425
|
|
426
|
+
class ARPAKITLibSO(BaseSO):
|
427
|
+
arpakitlib: bool = True
|
428
|
+
|
429
|
+
|
391
430
|
def add_needed_api_router_to_app(*, app: FastAPI):
|
392
431
|
api_router = APIRouter()
|
393
432
|
|
@@ -405,14 +444,14 @@ def add_needed_api_router_to_app(*, app: FastAPI):
|
|
405
444
|
|
406
445
|
@api_router.get(
|
407
446
|
"/arpakitlib",
|
408
|
-
response_model=
|
447
|
+
response_model=ARPAKITLibSO | ErrorSO,
|
409
448
|
status_code=starlette.status.HTTP_200_OK,
|
410
449
|
tags=["arpakitlib"]
|
411
450
|
)
|
412
451
|
async def _():
|
413
452
|
return APIJSONResponse(
|
414
453
|
status_code=starlette.status.HTTP_200_OK,
|
415
|
-
content=
|
454
|
+
content=ARPAKITLibSO(arpakitlib=True)
|
416
455
|
)
|
417
456
|
|
418
457
|
app.include_router(router=api_router, prefix="")
|
@@ -26,7 +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
|
-
|
29
|
+
not_raise_for_statuses_: list[int] | None = None,
|
30
30
|
timeout_: timedelta | float = timedelta(seconds=15).total_seconds(),
|
31
31
|
enable_logging_: bool = False,
|
32
32
|
**kwargs
|
@@ -61,9 +61,9 @@ def sync_make_http_request(
|
|
61
61
|
try:
|
62
62
|
response = requests.request(**kwargs)
|
63
63
|
if raise_for_status_:
|
64
|
-
if
|
64
|
+
if not_raise_for_statuses_ and response.status_code in not_raise_for_statuses_:
|
65
65
|
if enable_logging_:
|
66
|
-
_logger.info(f"ignored status {response.status_code}
|
66
|
+
_logger.info(f"ignored status {response.status_code} {method} {url} {params}")
|
67
67
|
else:
|
68
68
|
response.raise_for_status()
|
69
69
|
if enable_logging_:
|
@@ -72,7 +72,7 @@ def sync_make_http_request(
|
|
72
72
|
except Exception as exception:
|
73
73
|
if enable_logging_:
|
74
74
|
_logger.warning(
|
75
|
-
f"{tries_counter}/{max_tries_}
|
75
|
+
f"{tries_counter}/{max_tries_}, bad try {method} {url} {params}, exception={exception}"
|
76
76
|
)
|
77
77
|
if tries_counter >= max_tries_:
|
78
78
|
raise exception
|
@@ -89,7 +89,7 @@ async def async_make_http_request(
|
|
89
89
|
max_tries_: int = 9,
|
90
90
|
proxy_url_: str | None = None,
|
91
91
|
raise_for_status_: bool = False,
|
92
|
-
|
92
|
+
not_raise_for_statuses_: list[int] | None = None,
|
93
93
|
timeout_: timedelta | None = timedelta(seconds=15),
|
94
94
|
enable_logging_: bool = False,
|
95
95
|
**kwargs
|
@@ -120,21 +120,21 @@ async def async_make_http_request(
|
|
120
120
|
async with aiohttp.ClientSession(connector=proxy_connector) as session:
|
121
121
|
async with session.request(**kwargs) as response:
|
122
122
|
if raise_for_status_:
|
123
|
-
if
|
123
|
+
if not_raise_for_statuses_ and response.status in not_raise_for_statuses_:
|
124
124
|
if enable_logging_:
|
125
125
|
_logger.info(
|
126
|
-
f"ignored status {response.status}
|
126
|
+
f"ignored status {response.status} {method} {url} {params}"
|
127
127
|
)
|
128
128
|
else:
|
129
129
|
response.raise_for_status()
|
130
130
|
await response.read()
|
131
131
|
if enable_logging_:
|
132
|
-
_logger.info(f"good try
|
132
|
+
_logger.info(f"good try {method} {url} {params}")
|
133
133
|
return response
|
134
134
|
except Exception as exception:
|
135
135
|
if enable_logging_:
|
136
136
|
_logger.warning(
|
137
|
-
f"{tries_counter}/{max_tries_}
|
137
|
+
f"{tries_counter}/{max_tries_}, bad try {method} {url} {params}, exception={exception}"
|
138
138
|
)
|
139
139
|
if tries_counter >= max_tries_:
|
140
140
|
raise exception
|
arpakitlib/ar_logging_util.py
CHANGED
@@ -11,8 +11,8 @@ def init_log_file(*, log_filepath: str):
|
|
11
11
|
directory = os.path.dirname(log_filepath)
|
12
12
|
if directory and not os.path.exists(directory):
|
13
13
|
os.makedirs(directory, exist_ok=True)
|
14
|
-
if not os.path.exists(
|
15
|
-
with open(
|
14
|
+
if not os.path.exists(log_filepath):
|
15
|
+
with open(log_filepath, mode="w") as file:
|
16
16
|
file.write("")
|
17
17
|
|
18
18
|
|
arpakitlib/ar_retry_func_util.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
import asyncio
|
4
4
|
import hashlib
|
5
5
|
import logging
|
6
|
-
from datetime import datetime
|
6
|
+
from datetime import datetime, timedelta
|
7
7
|
from typing import Any
|
8
8
|
|
9
9
|
import pytz
|
@@ -85,8 +85,10 @@ class ScheduleUUSTAPIClient:
|
|
85
85
|
url=url,
|
86
86
|
headers=self.headers,
|
87
87
|
params=combine_dicts(params, self.auth_params()),
|
88
|
+
max_tries_=9,
|
88
89
|
proxy_url_=self.api_proxy_url,
|
89
90
|
raise_for_status_=True,
|
91
|
+
timeout_=timedelta(seconds=15),
|
90
92
|
**kwargs
|
91
93
|
)
|
92
94
|
json_data = await response.json()
|
@@ -55,7 +55,10 @@ class YookassaAPIClient:
|
|
55
55
|
method=method,
|
56
56
|
url=url,
|
57
57
|
headers=combine_dicts(self.headers, (headers if headers is not None else {})),
|
58
|
+
max_tries_=5,
|
59
|
+
raise_for_status_=True,
|
58
60
|
timeout_=self.timeout_,
|
61
|
+
not_raise_for_statuses_=[404],
|
59
62
|
auth=(self.shop_id, self.secret_key),
|
60
63
|
**kwargs
|
61
64
|
)
|
@@ -119,6 +122,9 @@ class YookassaAPIClient:
|
|
119
122
|
method=method,
|
120
123
|
url=url,
|
121
124
|
headers=combine_dicts(self.headers, (headers if headers is not None else {})),
|
125
|
+
max_tries_=5,
|
126
|
+
raise_for_status_=True,
|
127
|
+
not_raise_for_statuses_=[404],
|
122
128
|
timeout_=self.timeout_,
|
123
129
|
auth=aiohttp.BasicAuth(login=str(self.shop_id), password=self.secret_key),
|
124
130
|
**kwargs
|
@@ -135,7 +135,8 @@ arpakitlib/ar_aiogram_util.py,sha256=lv2aXUmXLm3f2JltT1i683de6MnTTp9b5HihjO4KM5s
|
|
135
135
|
arpakitlib/ar_api_key_util.py,sha256=E84JlJXiDHtxLQmV8BNHvqNKu_G8-Dox0XxknYJQ37Q,422
|
136
136
|
arpakitlib/ar_arpakit_lib_module_util.py,sha256=g9uWwTK2eEzmErqwYeVgXDYVMREN8m5CdmgEumAEQfw,5919
|
137
137
|
arpakitlib/ar_arpakit_project_template_util.py,sha256=c7yc8w2IvZGH5hH8eOpL7JuD005hUxZ0GVDcSkJF5iI,3705
|
138
|
-
arpakitlib/ar_arpakit_schedule_uust_api_client_util.py,sha256=
|
138
|
+
arpakitlib/ar_arpakit_schedule_uust_api_client_util.py,sha256=P4XdmQyPUwmrSGGad1XZszxWB2HMQKjyuDHCvOg0ys4,15787
|
139
|
+
arpakitlib/ar_arpakit_schedule_uust_site_util.py,sha256=8wLct9Gd4MWkXzB6nSmETAwTPLw8lfpWgx0LoWSAOvg,1643
|
139
140
|
arpakitlib/ar_arpakitlib_cli_util.py,sha256=208k_kWc-XHTYqL39k-rYrLcTKFF-3og21PVIsq5b2k,3171
|
140
141
|
arpakitlib/ar_base64_util.py,sha256=aZkg2cZTuAaP2IWeG_LXJ6RO7qhyskVwec-Lks0iM-k,676
|
141
142
|
arpakitlib/ar_base_worker_util.py,sha256=8xKNo_ob-VZsZ2THwM_cJDcA3Y4R-ruM7vKUfzKI94U,5600
|
@@ -143,7 +144,7 @@ arpakitlib/ar_cache_file_util.py,sha256=Fo2pH-Zqm966KWFBHG_pbiySGZvhIFCYqy7k1weR
|
|
143
144
|
arpakitlib/ar_class_util.py,sha256=Eb4orGm2EFSaHfmrY2A_Nis5iwFMDKFaz1_nxTnfmnQ,487
|
144
145
|
arpakitlib/ar_datetime_util.py,sha256=Xe1NiT9oPQzNSG7RVRkhukhbg4i-hhS5ImmV7sPUc8o,971
|
145
146
|
arpakitlib/ar_dict_util.py,sha256=cF5LQJ6tLqyGoEXfDljMDZrikeZoWPw7CgINHIFGvXM,419
|
146
|
-
arpakitlib/ar_dream_ai_api_client_util.py,sha256=
|
147
|
+
arpakitlib/ar_dream_ai_api_client_util.py,sha256=Z1oii_XSsgunYx17SdcHl54S4KPQti7-MJs0xXZ8vL0,2830
|
147
148
|
arpakitlib/ar_encrypt_decrypt_util.py,sha256=GhWnp7HHkbhwFVVCzO1H07m-5gryr4yjWsXjOaNQm1Y,520
|
148
149
|
arpakitlib/ar_enumeration_util.py,sha256=ZOkH1-duDcjQelJrdJ-nJ8h7wePFAgmpg_8e63Cyp0E,3072
|
149
150
|
arpakitlib/ar_exception_util.py,sha256=3hZKsj34TZVdmd4JAQz7w515smWqB8o3gTwAEjuMdnI,408
|
@@ -167,19 +168,19 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
|
|
167
168
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
|
168
169
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
|
169
170
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
|
170
|
-
arpakitlib/ar_fastapi_util.py,sha256=
|
171
|
+
arpakitlib/ar_fastapi_util.py,sha256=v4IVYpI7Vd72WwuiRH2b194pjZO66vhX0B9qNI_YFe4,27420
|
171
172
|
arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
|
172
173
|
arpakitlib/ar_file_util.py,sha256=GUdJYm1tUZnYpY-SIPRHAZBHGra8NKy1eYEI0D5AfhY,489
|
173
174
|
arpakitlib/ar_func_util.py,sha256=bCuWbSMoFXBaMNhb89sevj2oaXRk4Jk6Qjot8OXMDT4,1319
|
174
175
|
arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
|
175
|
-
arpakitlib/ar_http_request_util.py,sha256=
|
176
|
+
arpakitlib/ar_http_request_util.py,sha256=sXzpwtHKJJqoQhwMCIxcexDONqW6GAPBRCC0VmBj1tc,5052
|
176
177
|
arpakitlib/ar_ip_util.py,sha256=aEAa1Hvobh9DWX7cmBAPLqnXSTiKe2hRk-WJaiKMaI8,1009
|
177
178
|
arpakitlib/ar_json_db_util.py,sha256=CEyhIU4WuNmX5mqwBVYxUKSdpFelXvWmf_tJ1fuxMSE,7187
|
178
179
|
arpakitlib/ar_json_util.py,sha256=wJOsN8N7Rs7r8cTgMDXrmFa1GOkcD-LghqFEYXc8zGA,1083
|
179
180
|
arpakitlib/ar_jwt_util.py,sha256=Rhm4ywoTAn6yOV8NLjDASfAtAtheROxxDP40G3XjnuQ,761
|
180
181
|
arpakitlib/ar_list_of_dicts_to_xlsx.py,sha256=MyjEl4Jl4beLVZqLVQMMv0-XDtBD3Xh4Z_ZPDJeFu04,745
|
181
182
|
arpakitlib/ar_list_util.py,sha256=2woOAHAU8oTIiVjZ8GLnx15odEaoQUq3Q0JPxlufFF0,457
|
182
|
-
arpakitlib/ar_logging_util.py,sha256=
|
183
|
+
arpakitlib/ar_logging_util.py,sha256=V4jypypFG1cj4nXae7JiBnRRfm02OTnZSEermx-wlDY,1668
|
183
184
|
arpakitlib/ar_mongodb_util.py,sha256=2ECkTnGAZ92qxioL-fmN6R4yZOSr3bXdXLWTzT1C3vk,4038
|
184
185
|
arpakitlib/ar_need_type_util.py,sha256=GETiREPMEYhch-yU6T--Bdawlbb04Jp1Qy7cOsUlIeA,2228
|
185
186
|
arpakitlib/ar_openai_api_client_util.py,sha256=_XmlApvHFMSyjvZydPa_kASIt9LsFrZmSC7YEzIG8Bg,1806
|
@@ -187,9 +188,9 @@ arpakitlib/ar_operation_execution_util.py,sha256=YkftxZthr6knqW40mgq28y-zRXSTJPf
|
|
187
188
|
arpakitlib/ar_parse_command.py,sha256=-s61xcATIsfw1eV_iD3xi-grsitbGzSDoAFc5V0OFy4,3447
|
188
189
|
arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJAdo,945
|
189
190
|
arpakitlib/ar_rat_func_util.py,sha256=xDO3gcmZZ0VsTF5zwqyfrkct8FWcKmyl1KUwfdA1s4k,2009
|
190
|
-
arpakitlib/ar_retry_func_util.py,sha256=
|
191
|
+
arpakitlib/ar_retry_func_util.py,sha256=EQtXhn0RvMiyaes9HMDBgMh_WjMIaGwds01UrKKDaBM,2204
|
191
192
|
arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
|
192
|
-
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=
|
193
|
+
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=wvHiipgQUQiEBzQkb75h3QkG5x-CsU-653hu9KJw-jo,6980
|
193
194
|
arpakitlib/ar_settings_util.py,sha256=rnoTqbRuhiq7294D4crD5kbnU8-gNWJbwGU_Ls2gJoU,2199
|
194
195
|
arpakitlib/ar_sleep_util.py,sha256=OaLtRaJQWMkGjfj_mW1RB2P4RaSWsAIH8LUoXqsH0zM,1061
|
195
196
|
arpakitlib/ar_sqladmin_util.py,sha256=6Nv9VQssk9PB0piyuss__soYKdjVhdbIeXIv4AgUxmQ,2660
|
@@ -198,10 +199,10 @@ arpakitlib/ar_sqlalchemy_util.py,sha256=Hcg1THrDsSR_-8dsY1CG3NWPEv0FqCbkPXFXLtjl
|
|
198
199
|
arpakitlib/ar_ssh_runner_util.py,sha256=e9deuUdBW7Eh0Exx2nTBhk57SaOZYaJaSjNk8q6dbJk,6804
|
199
200
|
arpakitlib/ar_str_util.py,sha256=yU5gOwNXUQaH5b_tM5t6fXUn9oUcv5EQbVnq2wXXIpQ,3378
|
200
201
|
arpakitlib/ar_type_util.py,sha256=9C3ErtUVs0tAUqtK-foFzjJOykfBOntfCz2IogDOgfA,4134
|
201
|
-
arpakitlib/ar_yookassa_api_client_util.py,sha256=
|
202
|
+
arpakitlib/ar_yookassa_api_client_util.py,sha256=VozuZeCJjmLd1zj2BdC9WfiAQ3XYOrIMsdpNK-AUlm0,5347
|
202
203
|
arpakitlib/ar_zabbix_api_client_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
|
203
|
-
arpakitlib-1.7.
|
204
|
-
arpakitlib-1.7.
|
205
|
-
arpakitlib-1.7.
|
206
|
-
arpakitlib-1.7.
|
207
|
-
arpakitlib-1.7.
|
204
|
+
arpakitlib-1.7.232.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
205
|
+
arpakitlib-1.7.232.dist-info/METADATA,sha256=u5UvnCTGX9axtIbGyffi6UtPY6gVQEpExj4iOmi5qkU,3310
|
206
|
+
arpakitlib-1.7.232.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
207
|
+
arpakitlib-1.7.232.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
208
|
+
arpakitlib-1.7.232.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|