arpakitlib 1.7.212__py3-none-any.whl → 1.7.214__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 +19 -112
- arpakitlib/ar_fastapi_util.py +13 -8
- arpakitlib/ar_sqlalchemy_model_util.py +5 -6
- {arpakitlib-1.7.212.dist-info → arpakitlib-1.7.214.dist-info}/METADATA +1 -1
- {arpakitlib-1.7.212.dist-info → arpakitlib-1.7.214.dist-info}/RECORD +8 -8
- {arpakitlib-1.7.212.dist-info → arpakitlib-1.7.214.dist-info}/LICENSE +0 -0
- {arpakitlib-1.7.212.dist-info → arpakitlib-1.7.214.dist-info}/WHEEL +0 -0
- {arpakitlib-1.7.212.dist-info → arpakitlib-1.7.214.dist-info}/entry_points.txt +0 -0
@@ -15,9 +15,7 @@ import cachetools
|
|
15
15
|
from aiohttp import ClientResponse, ClientTimeout, ClientResponseError
|
16
16
|
from pydantic import ConfigDict, BaseModel
|
17
17
|
|
18
|
-
from arpakitlib.ar_dict_util import combine_dicts
|
19
18
|
from arpakitlib.ar_enumeration_util import Enumeration
|
20
|
-
from arpakitlib.ar_json_util import safely_transfer_obj_to_json_str
|
21
19
|
from arpakitlib.ar_sleep_util import async_safe_sleep
|
22
20
|
from arpakitlib.ar_type_util import raise_for_type
|
23
21
|
|
@@ -52,8 +50,20 @@ class Months(Enumeration):
|
|
52
50
|
class BaseAPIModel(BaseModel):
|
53
51
|
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
|
54
52
|
|
55
|
-
|
56
|
-
|
53
|
+
|
54
|
+
class CurrentSemesterAPIModel(BaseAPIModel):
|
55
|
+
id: int
|
56
|
+
creation_dt: datetime
|
57
|
+
sync_from_uust_api_dt: datetime
|
58
|
+
value: str
|
59
|
+
raw_value: str
|
60
|
+
|
61
|
+
|
62
|
+
class CurrentWeekAPIModel(BaseAPIModel):
|
63
|
+
id: int
|
64
|
+
creation_dt: datetime
|
65
|
+
sync_from_uust_api_dt: datetime
|
66
|
+
value: str
|
57
67
|
|
58
68
|
|
59
69
|
class GroupAPIModel(BaseAPIModel):
|
@@ -67,15 +77,6 @@ class GroupAPIModel(BaseAPIModel):
|
|
67
77
|
difference_level: int | None = None
|
68
78
|
uust_api_data: dict[str, Any]
|
69
79
|
|
70
|
-
arpakit_uust_api_data: dict[str, Any]
|
71
|
-
|
72
|
-
@classmethod
|
73
|
-
def from_arpakit_uust_api_data(cls, arpakit_uust_api_data: dict[str, Any]) -> GroupAPIModel:
|
74
|
-
return GroupAPIModel.model_validate(combine_dicts(
|
75
|
-
arpakit_uust_api_data,
|
76
|
-
{"arpakit_uust_api_data": arpakit_uust_api_data}
|
77
|
-
))
|
78
|
-
|
79
80
|
|
80
81
|
class TeacherAPIModel(BaseAPIModel):
|
81
82
|
id: int
|
@@ -94,15 +95,6 @@ class TeacherAPIModel(BaseAPIModel):
|
|
94
95
|
difference_level: int | None
|
95
96
|
uust_api_data: dict[str, Any]
|
96
97
|
|
97
|
-
arpakit_uust_api_data: dict[str, Any]
|
98
|
-
|
99
|
-
@classmethod
|
100
|
-
def from_arpakit_uust_api_data(cls, arpakit_uust_api_data: dict[str, Any]) -> TeacherAPIModel:
|
101
|
-
return TeacherAPIModel.model_validate(combine_dicts(
|
102
|
-
arpakit_uust_api_data,
|
103
|
-
{"arpakit_uust_api_data": arpakit_uust_api_data}
|
104
|
-
))
|
105
|
-
|
106
98
|
|
107
99
|
class GroupLessonAPIModel(BaseAPIModel):
|
108
100
|
id: int
|
@@ -125,29 +117,6 @@ class GroupLessonAPIModel(BaseAPIModel):
|
|
125
117
|
teacher: TeacherAPIModel | None
|
126
118
|
uust_api_data: dict[str, Any]
|
127
119
|
|
128
|
-
arpakit_uust_api_data: dict[str, Any]
|
129
|
-
|
130
|
-
@classmethod
|
131
|
-
def from_arpakit_uust_api_data(cls, arpakit_uust_api_data: dict[str, Any]) -> GroupLessonAPIModel:
|
132
|
-
return GroupLessonAPIModel.model_validate(combine_dicts(
|
133
|
-
arpakit_uust_api_data,
|
134
|
-
{"arpakit_uust_api_data": arpakit_uust_api_data},
|
135
|
-
{
|
136
|
-
"group": GroupAPIModel.from_arpakit_uust_api_data(
|
137
|
-
arpakit_uust_api_data=arpakit_uust_api_data["group"]
|
138
|
-
)
|
139
|
-
},
|
140
|
-
{
|
141
|
-
"teacher": (
|
142
|
-
TeacherAPIModel.from_arpakit_uust_api_data(
|
143
|
-
arpakit_uust_api_data=arpakit_uust_api_data["teacher"]
|
144
|
-
)
|
145
|
-
if arpakit_uust_api_data["teacher"] is not None
|
146
|
-
else None
|
147
|
-
)
|
148
|
-
},
|
149
|
-
))
|
150
|
-
|
151
120
|
def compare_type(self, *types: str | list[str]) -> bool:
|
152
121
|
type_ = self.type.strip().lower()
|
153
122
|
for type__ in types:
|
@@ -184,26 +153,6 @@ class TeacherLessonAPIModel(BaseAPIModel):
|
|
184
153
|
groups: list[GroupAPIModel]
|
185
154
|
uust_api_data: dict[str, Any]
|
186
155
|
|
187
|
-
arpakit_uust_api_data: dict[str, Any]
|
188
|
-
|
189
|
-
@classmethod
|
190
|
-
def from_arpakit_uust_api_data(cls, arpakit_uust_api_data: dict[str, Any]) -> TeacherLessonAPIModel:
|
191
|
-
return TeacherLessonAPIModel.model_validate(combine_dicts(
|
192
|
-
arpakit_uust_api_data,
|
193
|
-
{"arpakit_uust_api_data": arpakit_uust_api_data},
|
194
|
-
{
|
195
|
-
"teacher": TeacherAPIModel.from_arpakit_uust_api_data(
|
196
|
-
arpakit_uust_api_data=arpakit_uust_api_data["teacher"]
|
197
|
-
)
|
198
|
-
},
|
199
|
-
{
|
200
|
-
"groups": [
|
201
|
-
GroupAPIModel.from_arpakit_uust_api_data(arpakit_uust_api_data=d)
|
202
|
-
for d in arpakit_uust_api_data["groups"]
|
203
|
-
]
|
204
|
-
},
|
205
|
-
))
|
206
|
-
|
207
156
|
def compare_type(self, *types: str | list[str]) -> bool:
|
208
157
|
type_ = self.type.strip().lower()
|
209
158
|
for type__ in types:
|
@@ -219,39 +168,6 @@ class TeacherLessonAPIModel(BaseAPIModel):
|
|
219
168
|
return False
|
220
169
|
|
221
170
|
|
222
|
-
class CurrentSemesterAPIModel(BaseAPIModel):
|
223
|
-
id: int
|
224
|
-
creation_dt: datetime
|
225
|
-
sync_from_uust_api_dt: datetime
|
226
|
-
value: str
|
227
|
-
raw_value: str
|
228
|
-
|
229
|
-
arpakit_uust_api_data: dict[str, Any]
|
230
|
-
|
231
|
-
@classmethod
|
232
|
-
def from_arpakit_uust_api_data(cls, *, arpakit_uust_api_data: dict[str, Any]) -> CurrentSemesterAPIModel:
|
233
|
-
return CurrentSemesterAPIModel.model_validate(combine_dicts(
|
234
|
-
arpakit_uust_api_data,
|
235
|
-
{"arpakit_uust_api_data": arpakit_uust_api_data}
|
236
|
-
))
|
237
|
-
|
238
|
-
|
239
|
-
class CurrentWeekAPIModel(BaseAPIModel):
|
240
|
-
id: int
|
241
|
-
creation_dt: datetime
|
242
|
-
sync_from_uust_api_dt: datetime
|
243
|
-
value: str
|
244
|
-
|
245
|
-
arpakit_uust_api_data: dict[str, Any]
|
246
|
-
|
247
|
-
@classmethod
|
248
|
-
def from_arpakit_uust_api_data(cls, *, arpakit_uust_api_data: dict[str, Any]) -> CurrentWeekAPIModel:
|
249
|
-
return CurrentWeekAPIModel.model_validate(combine_dicts(
|
250
|
-
arpakit_uust_api_data,
|
251
|
-
{"arpakit_uust_api_data": arpakit_uust_api_data}
|
252
|
-
))
|
253
|
-
|
254
|
-
|
255
171
|
class WeatherInUfaAPIModel(BaseAPIModel):
|
256
172
|
temperature: float
|
257
173
|
temperature_feels_like: float
|
@@ -263,15 +179,6 @@ class WeatherInUfaAPIModel(BaseAPIModel):
|
|
263
179
|
has_snow: bool
|
264
180
|
data: dict
|
265
181
|
|
266
|
-
arpakit_uust_api_data: dict[str, Any]
|
267
|
-
|
268
|
-
@classmethod
|
269
|
-
def from_arpakit_uust_api_data(cls, arpakit_uust_api_data: dict[float, Any]) -> WeatherInUfaAPIModel:
|
270
|
-
return WeatherInUfaAPIModel.model_validate(combine_dicts(
|
271
|
-
arpakit_uust_api_data,
|
272
|
-
{"arpakit_uust_api_data": arpakit_uust_api_data}
|
273
|
-
))
|
274
|
-
|
275
182
|
|
276
183
|
class ARPAKITScheduleUUSTAPIClient:
|
277
184
|
def __init__(
|
@@ -280,7 +187,7 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
280
187
|
base_url: str = "https://api.schedule-uust.arpakit.com/api/v1",
|
281
188
|
api_key: str | None = "viewer",
|
282
189
|
use_cache: bool = False,
|
283
|
-
cache_ttl:
|
190
|
+
cache_ttl: timedelta | None = timedelta(minutes=10)
|
284
191
|
):
|
285
192
|
self._logger = logging.getLogger(__name__)
|
286
193
|
self.api_key = api_key
|
@@ -290,15 +197,15 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
290
197
|
self.base_url = base_url
|
291
198
|
self.headers = {"Content-Type": "application/json"}
|
292
199
|
if api_key is not None:
|
293
|
-
self.headers.update({"apikey": api_key})
|
200
|
+
self.headers.update({"apikey": self.api_key})
|
294
201
|
self.use_cache = use_cache
|
295
202
|
self.cache_ttl = cache_ttl
|
296
203
|
if cache_ttl is not None:
|
297
|
-
self.ttl_cache = cachetools.TTLCache(maxsize=100, ttl=cache_ttl)
|
204
|
+
self.ttl_cache = cachetools.TTLCache(maxsize=100, ttl=cache_ttl.total_seconds())
|
298
205
|
else:
|
299
206
|
self.ttl_cache = None
|
300
207
|
|
301
|
-
def
|
208
|
+
def clear_cache(self):
|
302
209
|
if self.ttl_cache is not None:
|
303
210
|
self.ttl_cache.clear()
|
304
211
|
|
@@ -350,7 +257,7 @@ class ARPAKITScheduleUUSTAPIClient:
|
|
350
257
|
return False
|
351
258
|
|
352
259
|
async def auth_healthcheck(self) -> bool:
|
353
|
-
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "
|
260
|
+
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "check_auth"))
|
354
261
|
response.raise_for_status()
|
355
262
|
json_data = await response.json()
|
356
263
|
return json_data["data"]["auth_healthcheck"]
|
arpakitlib/ar_fastapi_util.py
CHANGED
@@ -391,7 +391,10 @@ def add_needed_api_router_to_app(*, app: FastAPI):
|
|
391
391
|
async def _():
|
392
392
|
return APIJSONResponse(
|
393
393
|
status_code=starlette.status.HTTP_200_OK,
|
394
|
-
content=RawDataSO(data={
|
394
|
+
content=RawDataSO(data={
|
395
|
+
"healthcheck": "healthcheck",
|
396
|
+
"is_ok": True
|
397
|
+
})
|
395
398
|
)
|
396
399
|
|
397
400
|
@api_router.get(
|
@@ -449,8 +452,8 @@ class BaseAPIAuthData(BaseModel):
|
|
449
452
|
token_string: str | None = None
|
450
453
|
api_key_string: str | None = None
|
451
454
|
|
452
|
-
|
453
|
-
|
455
|
+
is_token_correct: bool | None = None
|
456
|
+
is_api_key_correct: bool | None = None
|
454
457
|
|
455
458
|
|
456
459
|
def base_api_auth(
|
@@ -580,7 +583,7 @@ def base_api_auth(
|
|
580
583
|
)
|
581
584
|
if is_async_object(validate_api_key_func_data):
|
582
585
|
validate_api_key_func_data = await validate_api_key_func_data
|
583
|
-
api_auth_data.
|
586
|
+
api_auth_data.is_api_key_correct = validate_api_key_func_data
|
584
587
|
|
585
588
|
# token
|
586
589
|
|
@@ -595,25 +598,27 @@ def base_api_auth(
|
|
595
598
|
)
|
596
599
|
if is_async_object(validate_token_func_data):
|
597
600
|
validate_token_func_data_data = await validate_token_func_data
|
598
|
-
api_auth_data.
|
601
|
+
api_auth_data.is_token_correct = validate_token_func_data_data
|
599
602
|
|
600
603
|
# api_key
|
601
604
|
|
602
605
|
if require_correct_api_key:
|
603
|
-
if not api_auth_data.
|
606
|
+
if not api_auth_data.is_api_key_correct:
|
604
607
|
raise APIException(
|
605
608
|
status_code=starlette.status.HTTP_401_UNAUTHORIZED,
|
606
609
|
error_code=BaseAPIErrorCodes.cannot_authorize,
|
607
|
-
|
610
|
+
error_description="not api_auth_data.is_api_key_correct",
|
611
|
+
error_data=safely_transfer_obj_to_json_str_to_json_obj(api_auth_data.model_dump()),
|
608
612
|
)
|
609
613
|
|
610
614
|
# token
|
611
615
|
|
612
616
|
if require_correct_token:
|
613
|
-
if not api_auth_data.
|
617
|
+
if not api_auth_data.is_token_correct:
|
614
618
|
raise APIException(
|
615
619
|
status_code=starlette.status.HTTP_401_UNAUTHORIZED,
|
616
620
|
error_code=BaseAPIErrorCodes.cannot_authorize,
|
621
|
+
error_description="not api_auth_data.is_token_correct",
|
617
622
|
error_data=safely_transfer_obj_to_json_str_to_json_obj(api_auth_data.model_dump())
|
618
623
|
)
|
619
624
|
|
@@ -4,8 +4,7 @@ from datetime import datetime, timedelta
|
|
4
4
|
from typing import Any
|
5
5
|
from uuid import uuid4
|
6
6
|
|
7
|
-
from sqlalchemy import inspect, INTEGER, TEXT, TIMESTAMP, func
|
8
|
-
from sqlalchemy.dialects.postgresql import JSONB
|
7
|
+
from sqlalchemy import inspect, INTEGER, TEXT, TIMESTAMP, func, JSON
|
9
8
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
10
9
|
|
11
10
|
from arpakitlib.ar_datetime_util import now_utc_dt
|
@@ -103,7 +102,7 @@ class StoryLogDBM(SimpleDBM):
|
|
103
102
|
)
|
104
103
|
title: Mapped[str | None] = mapped_column(TEXT, index=True, default=None, nullable=True)
|
105
104
|
data: Mapped[dict[str, Any]] = mapped_column(
|
106
|
-
|
105
|
+
JSON, insert_default={}, server_default="{}", index=True, nullable=False
|
107
106
|
)
|
108
107
|
|
109
108
|
|
@@ -131,13 +130,13 @@ class OperationDBM(SimpleDBM):
|
|
131
130
|
execution_start_dt: Mapped[datetime | None] = mapped_column(TIMESTAMP(timezone=True), nullable=True)
|
132
131
|
execution_finish_dt: Mapped[datetime | None] = mapped_column(TIMESTAMP(timezone=True), nullable=True)
|
133
132
|
input_data: Mapped[dict[str, Any]] = mapped_column(
|
134
|
-
|
133
|
+
JSON,
|
135
134
|
insert_default={},
|
136
135
|
server_default="{}",
|
137
136
|
nullable=False
|
138
137
|
)
|
139
|
-
output_data: Mapped[dict[str, Any]] = mapped_column(
|
140
|
-
error_data: Mapped[dict[str, Any]] = mapped_column(
|
138
|
+
output_data: Mapped[dict[str, Any]] = mapped_column(JSON, insert_default={}, server_default="{}", nullable=False)
|
139
|
+
error_data: Mapped[dict[str, Any]] = mapped_column(JSON, insert_default={}, server_default="{}", nullable=False)
|
141
140
|
|
142
141
|
def raise_if_executed_with_error(self):
|
143
142
|
if self.status == self.Statuses.executed_with_error:
|
@@ -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=8kJTOliAmre0zOtpsF_FF_SCb5Pwmdfl2iSrdPDnc-s,15682
|
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
|
@@ -152,7 +152,7 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
|
|
152
152
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
|
153
153
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
|
154
154
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
|
155
|
-
arpakitlib/ar_fastapi_util.py,sha256=
|
155
|
+
arpakitlib/ar_fastapi_util.py,sha256=9mEv9eY6RmUSIjrJMOIT_cf8Rs1K7RPU6BO09Z-CREA,26402
|
156
156
|
arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
|
157
157
|
arpakitlib/ar_file_util.py,sha256=GUdJYm1tUZnYpY-SIPRHAZBHGra8NKy1eYEI0D5AfhY,489
|
158
158
|
arpakitlib/ar_func_util.py,sha256=bCuWbSMoFXBaMNhb89sevj2oaXRk4Jk6Qjot8OXMDT4,1319
|
@@ -176,15 +176,15 @@ arpakitlib/ar_schedule_uust_api_client_util.py,sha256=0Ns0mMEXYEkVmP6YTAXHyNcrhN
|
|
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
|
179
|
-
arpakitlib/ar_sqlalchemy_model_util.py,sha256=
|
179
|
+
arpakitlib/ar_sqlalchemy_model_util.py,sha256=DGbXcqD2hukzAiO0aQDUkJ5xOvi3yYnMKzI5y0pMXzs,6217
|
180
180
|
arpakitlib/ar_sqlalchemy_util.py,sha256=Hcg1THrDsSR_-8dsY1CG3NWPEv0FqCbkPXFXLtjlSJ0,4207
|
181
181
|
arpakitlib/ar_ssh_runner_util.py,sha256=e9deuUdBW7Eh0Exx2nTBhk57SaOZYaJaSjNk8q6dbJk,6804
|
182
182
|
arpakitlib/ar_str_util.py,sha256=yU5gOwNXUQaH5b_tM5t6fXUn9oUcv5EQbVnq2wXXIpQ,3378
|
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.214.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
187
|
+
arpakitlib-1.7.214.dist-info/METADATA,sha256=B4YYOAdNRhvcxTgijj09N6fhr_FF1Se1EKUJt-LuhHU,3176
|
188
|
+
arpakitlib-1.7.214.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
189
|
+
arpakitlib-1.7.214.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
190
|
+
arpakitlib-1.7.214.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|