arpakitlib 1.8.307__py3-none-any.whl → 1.8.322__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 arpakitlib might be problematic. Click here for more details.
- arpakitlib/ar_ensure_sqlalchemy_check_constraints.py +4 -2
- arpakitlib/ar_generate_connection_url_util.py +79 -0
- arpakitlib/ar_mongodb_util.py +0 -23
- arpakitlib/ar_settings_util.py +24 -3
- arpakitlib/ar_sqlalchemy_drop_check_constraints.py +3 -0
- arpakitlib/ar_sqlalchemy_util.py +3 -40
- arpakitlib/ar_uppercase_env_keys.py +24 -13
- arpakitlib/ar_yookassa_api_client_util.py +175 -0
- arpakitlib/include_fastapi_routers_from_dir.py +46 -0
- {arpakitlib-1.8.307.dist-info → arpakitlib-1.8.322.dist-info}/METADATA +2 -2
- {arpakitlib-1.8.307.dist-info → arpakitlib-1.8.322.dist-info}/RECORD +14 -16
- arpakitlib/ar_additional_model_util.py +0 -40
- arpakitlib/ar_arpakit_schedule_uust_api_client_util.py +0 -422
- arpakitlib/ar_arpakit_schedule_uust_site_util.py +0 -68
- arpakitlib/ar_generate_celery_url.py +0 -71
- arpakitlib/ar_schedule_uust_api_client_util.py +0 -227
- {arpakitlib-1.8.307.dist-info → arpakitlib-1.8.322.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.307.dist-info → arpakitlib-1.8.322.dist-info}/entry_points.txt +0 -0
- {arpakitlib-1.8.307.dist-info → arpakitlib-1.8.322.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
# arpakit
|
|
2
|
-
|
|
3
|
-
import asyncio
|
|
4
|
-
import hashlib
|
|
5
|
-
import logging
|
|
6
|
-
from datetime import datetime, timedelta
|
|
7
|
-
from typing import Any
|
|
8
|
-
|
|
9
|
-
import pytz
|
|
10
|
-
from aiohttp import ClientResponse
|
|
11
|
-
|
|
12
|
-
from arpakitlib.ar_dict_util import combine_dicts
|
|
13
|
-
from arpakitlib.ar_http_request_util import async_make_http_request
|
|
14
|
-
|
|
15
|
-
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class ScheduleUUSTAPIClient:
|
|
19
|
-
def __init__(
|
|
20
|
-
self,
|
|
21
|
-
*,
|
|
22
|
-
api_login: str,
|
|
23
|
-
api_password: str | None = None,
|
|
24
|
-
api_password_first_part: str | None = None,
|
|
25
|
-
api_url: str = "https://isu.uust.ru/api/schedule_v2",
|
|
26
|
-
api_proxy_url: str | None = None
|
|
27
|
-
):
|
|
28
|
-
self._logger = logging.getLogger(self.__class__.__name__)
|
|
29
|
-
self.api_login = api_login
|
|
30
|
-
self.api_password = api_password
|
|
31
|
-
self.api_password_first_part = api_password_first_part
|
|
32
|
-
self.api_url = api_url
|
|
33
|
-
self.api_proxy_url = api_proxy_url
|
|
34
|
-
self.headers = {
|
|
35
|
-
"Accept": (
|
|
36
|
-
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;"
|
|
37
|
-
"q=0.8,application/signed-exchange;v=b3;q=0.7"
|
|
38
|
-
),
|
|
39
|
-
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
40
|
-
"Accept-Language": "en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7",
|
|
41
|
-
"User-Agent": (
|
|
42
|
-
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async def _async_make_http_request(
|
|
47
|
-
self,
|
|
48
|
-
*,
|
|
49
|
-
method: str = "GET",
|
|
50
|
-
url: str,
|
|
51
|
-
params: dict[str, Any] | None = None,
|
|
52
|
-
**kwargs
|
|
53
|
-
) -> ClientResponse:
|
|
54
|
-
response = await async_make_http_request(
|
|
55
|
-
method=method,
|
|
56
|
-
url=url,
|
|
57
|
-
headers=self.headers,
|
|
58
|
-
params=combine_dicts(params, self.auth_params()),
|
|
59
|
-
max_tries_=9,
|
|
60
|
-
proxy_url_=self.api_proxy_url,
|
|
61
|
-
raise_for_status_=True,
|
|
62
|
-
timeout_=timedelta(seconds=15),
|
|
63
|
-
**kwargs
|
|
64
|
-
)
|
|
65
|
-
json_data = await response.json()
|
|
66
|
-
if "error" in json_data.keys():
|
|
67
|
-
raise Exception(f"error in json_data, {json_data}")
|
|
68
|
-
return response
|
|
69
|
-
|
|
70
|
-
def auth_params(self) -> dict[str, Any]:
|
|
71
|
-
if self.api_password:
|
|
72
|
-
return {
|
|
73
|
-
"login": self.api_login,
|
|
74
|
-
"pass": self.api_password
|
|
75
|
-
}
|
|
76
|
-
elif self.api_password_first_part:
|
|
77
|
-
return {
|
|
78
|
-
"login": self.api_login,
|
|
79
|
-
"pass": self.generate_v2_token()
|
|
80
|
-
}
|
|
81
|
-
else:
|
|
82
|
-
return {}
|
|
83
|
-
|
|
84
|
-
@classmethod
|
|
85
|
-
def hash_new_token(cls, token: str) -> str:
|
|
86
|
-
sha256 = hashlib.sha256()
|
|
87
|
-
sha256.update(token.encode('utf-8'))
|
|
88
|
-
return sha256.hexdigest()
|
|
89
|
-
|
|
90
|
-
@classmethod
|
|
91
|
-
def generate_new_v2_token(cls, password_first_part: str) -> str:
|
|
92
|
-
return cls.hash_new_token(
|
|
93
|
-
password_first_part + datetime.now(tz=pytz.timezone("Asia/Yekaterinburg")).strftime("%Y-%m-%d")
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
def generate_v2_token(self) -> str:
|
|
97
|
-
return self.generate_new_v2_token(password_first_part=self.api_password_first_part)
|
|
98
|
-
|
|
99
|
-
async def get_current_week(self) -> int:
|
|
100
|
-
"""
|
|
101
|
-
response.json example
|
|
102
|
-
{
|
|
103
|
-
'data': [15]
|
|
104
|
-
}
|
|
105
|
-
"""
|
|
106
|
-
|
|
107
|
-
response = await self._async_make_http_request(
|
|
108
|
-
url=self.api_url,
|
|
109
|
-
params={"ask": "get_current_week"}
|
|
110
|
-
)
|
|
111
|
-
json_data = await response.json()
|
|
112
|
-
return json_data["data"][0]
|
|
113
|
-
|
|
114
|
-
async def get_current_semester(self) -> str:
|
|
115
|
-
"""
|
|
116
|
-
response.json example
|
|
117
|
-
{
|
|
118
|
-
'data': ['Осенний семестр 2023/2024']
|
|
119
|
-
}
|
|
120
|
-
"""
|
|
121
|
-
|
|
122
|
-
response = await self._async_make_http_request(
|
|
123
|
-
url=self.api_url,
|
|
124
|
-
params={"ask": "get_current_semestr"}
|
|
125
|
-
)
|
|
126
|
-
json_data = await response.json()
|
|
127
|
-
return json_data["data"][0]
|
|
128
|
-
|
|
129
|
-
async def get_groups(self) -> list[dict[str, Any]]:
|
|
130
|
-
"""
|
|
131
|
-
response.json example
|
|
132
|
-
{
|
|
133
|
-
"data": {
|
|
134
|
-
"4438": {
|
|
135
|
-
"group_id": 4438,
|
|
136
|
-
"group_title": "АРКТ-101А",
|
|
137
|
-
"faculty": "",
|
|
138
|
-
"course": 1
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
"""
|
|
143
|
-
|
|
144
|
-
response = await self._async_make_http_request(
|
|
145
|
-
url=self.api_url,
|
|
146
|
-
params={"ask": "get_group_list"}
|
|
147
|
-
)
|
|
148
|
-
json_data = await response.json()
|
|
149
|
-
return list(json_data["data"].values())
|
|
150
|
-
|
|
151
|
-
async def get_group_lessons(self, group_id: int, semester: str | None = None) -> list[dict[str, Any]]:
|
|
152
|
-
params = {
|
|
153
|
-
"ask": "get_group_schedule",
|
|
154
|
-
"id": group_id
|
|
155
|
-
}
|
|
156
|
-
if semester is not None:
|
|
157
|
-
params["semester"] = semester
|
|
158
|
-
response = await self._async_make_http_request(
|
|
159
|
-
url=self.api_url,
|
|
160
|
-
params=params
|
|
161
|
-
)
|
|
162
|
-
json_data = await response.json()
|
|
163
|
-
return json_data["data"]
|
|
164
|
-
|
|
165
|
-
async def get_teachers(self) -> list[dict[str, Any]]:
|
|
166
|
-
response = await self._async_make_http_request(
|
|
167
|
-
url=self.api_url,
|
|
168
|
-
params={"ask": "get_teacher_list"}
|
|
169
|
-
)
|
|
170
|
-
json_data = await response.json()
|
|
171
|
-
return list(json_data["data"].values())
|
|
172
|
-
|
|
173
|
-
async def get_teacher_lessons(self, teacher_id: int, semester: str | None = None) -> list[dict[str, Any]]:
|
|
174
|
-
params = {"ask": "get_teacher_schedule", "id": teacher_id}
|
|
175
|
-
if semester is not None:
|
|
176
|
-
params["semester"] = semester
|
|
177
|
-
response = await self._async_make_http_request(
|
|
178
|
-
url=self.api_url,
|
|
179
|
-
params=params
|
|
180
|
-
)
|
|
181
|
-
json_data = await response.json()
|
|
182
|
-
return json_data["data"]
|
|
183
|
-
|
|
184
|
-
async def check_conn(self):
|
|
185
|
-
await self.get_current_week()
|
|
186
|
-
self._logger.info(f"connection is good")
|
|
187
|
-
|
|
188
|
-
async def is_conn_good(self):
|
|
189
|
-
try:
|
|
190
|
-
await self.check_conn()
|
|
191
|
-
except Exception as e:
|
|
192
|
-
self._logger.error(f"connection is bad, {e}")
|
|
193
|
-
return False
|
|
194
|
-
return True
|
|
195
|
-
|
|
196
|
-
async def check_all(self) -> dict[str, Any]:
|
|
197
|
-
current_semester = await self.get_current_semester()
|
|
198
|
-
self._logger.info(f"current_semester: {current_semester}")
|
|
199
|
-
|
|
200
|
-
current_week = await self.get_current_week()
|
|
201
|
-
self._logger.info(f"current_week: {current_week}")
|
|
202
|
-
|
|
203
|
-
groups = await self.get_groups()
|
|
204
|
-
self._logger.info(f"groups len: {len(groups)}")
|
|
205
|
-
|
|
206
|
-
teachers = await self.get_teachers()
|
|
207
|
-
self._logger.info(f"teachers len: {len(teachers)}")
|
|
208
|
-
|
|
209
|
-
return {
|
|
210
|
-
"current_semester": current_semester,
|
|
211
|
-
"current_week": current_week,
|
|
212
|
-
"len(groups)": len(groups),
|
|
213
|
-
"len(teachers)": len(teachers)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
def __example():
|
|
218
|
-
pass
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
async def __async_example():
|
|
222
|
-
pass
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if __name__ == '__main__':
|
|
226
|
-
__example()
|
|
227
|
-
asyncio.run(__async_example())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|