arpakitlib 1.6.91__py3-none-any.whl → 1.6.92__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_aiogram_util.py +10 -9
- arpakitlib/ar_dream_ai_api_client_util.py +20 -50
- arpakitlib/ar_fastapi_util.py +5 -1
- arpakitlib/ar_schedule_uust_api_client_util.py +2 -2
- {arpakitlib-1.6.91.dist-info → arpakitlib-1.6.92.dist-info}/METADATA +1 -1
- {arpakitlib-1.6.91.dist-info → arpakitlib-1.6.92.dist-info}/RECORD +10 -10
- {arpakitlib-1.6.91.dist-info → arpakitlib-1.6.92.dist-info}/LICENSE +0 -0
- {arpakitlib-1.6.91.dist-info → arpakitlib-1.6.92.dist-info}/NOTICE +0 -0
- {arpakitlib-1.6.91.dist-info → arpakitlib-1.6.92.dist-info}/WHEEL +0 -0
- {arpakitlib-1.6.91.dist-info → arpakitlib-1.6.92.dist-info}/entry_points.txt +0 -0
arpakitlib/ar_aiogram_util.py
CHANGED
@@ -326,19 +326,20 @@ class BaseTransmittedTgBotData(BaseModel):
|
|
326
326
|
model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True, from_attributes=True)
|
327
327
|
|
328
328
|
|
329
|
-
def create_aiogram_tg_bot(*, tg_bot_token: str, tg_bot_proxy_url: str | None = None) -> Bot:
|
330
|
-
|
329
|
+
def create_aiogram_tg_bot(*, tg_bot_token: str, tg_bot_proxy_url: str | None = None, **kwargs) -> Bot:
|
330
|
+
kwargs["token"] = tg_bot_token
|
331
|
+
|
331
332
|
if tg_bot_proxy_url:
|
332
|
-
session = AiohttpSession(proxy=tg_bot_proxy_url)
|
333
|
-
|
334
|
-
|
335
|
-
default=DefaultBotProperties(
|
333
|
+
kwargs["session"] = AiohttpSession(proxy=tg_bot_proxy_url)
|
334
|
+
|
335
|
+
if kwargs.get("default") is None:
|
336
|
+
kwargs["default"] = DefaultBotProperties(
|
336
337
|
parse_mode=ParseMode.HTML,
|
337
338
|
disable_notification=False,
|
338
339
|
link_preview_is_disabled=True
|
339
|
-
)
|
340
|
-
|
341
|
-
)
|
340
|
+
)
|
341
|
+
|
342
|
+
tg_bot = Bot(**kwargs)
|
342
343
|
|
343
344
|
return tg_bot
|
344
345
|
|
@@ -2,16 +2,14 @@
|
|
2
2
|
|
3
3
|
import asyncio
|
4
4
|
import logging
|
5
|
-
from
|
5
|
+
from typing import Any
|
6
6
|
from urllib.parse import urljoin
|
7
7
|
|
8
|
-
import
|
9
|
-
from aiohttp import ClientResponseError, ClientResponse, ClientTimeout
|
8
|
+
from aiohttp import ClientResponse
|
10
9
|
from pydantic import ConfigDict, BaseModel
|
11
10
|
|
12
11
|
from arpakitlib.ar_base64_util import convert_base64_string_to_bytes
|
13
|
-
from arpakitlib.
|
14
|
-
from arpakitlib.ar_sleep_util import async_safe_sleep
|
12
|
+
from arpakitlib.ar_http_request_util import async_make_http_request
|
15
13
|
|
16
14
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
17
15
|
|
@@ -19,9 +17,6 @@ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
|
19
17
|
class BaseAPIModel(BaseModel):
|
20
18
|
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
|
21
19
|
|
22
|
-
def simple_json(self) -> str:
|
23
|
-
return safely_transfer_to_json_str(self.model_dump(mode="json"))
|
24
|
-
|
25
20
|
|
26
21
|
class GenerateImageFromNumberResApiModel(BaseAPIModel):
|
27
22
|
image_filename: str
|
@@ -39,7 +34,7 @@ class DreamAIAPIClient:
|
|
39
34
|
self,
|
40
35
|
*,
|
41
36
|
base_url: str = "https://api.dream_ai.arpakit.com/api/v1",
|
42
|
-
api_key: str | None =
|
37
|
+
api_key: str | None = "1"
|
43
38
|
):
|
44
39
|
self._logger = logging.getLogger(__name__)
|
45
40
|
self.api_key = api_key
|
@@ -51,60 +46,35 @@ class DreamAIAPIClient:
|
|
51
46
|
if api_key is not None:
|
52
47
|
self.headers.update({"apikey": api_key})
|
53
48
|
|
54
|
-
async def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
self._logger.info(f"{method} {url}")
|
66
|
-
try:
|
67
|
-
async with aiohttp.ClientSession() as session:
|
68
|
-
async with session.request(**kwargs) as response:
|
69
|
-
await response.read()
|
70
|
-
return response
|
71
|
-
except Exception as err:
|
72
|
-
self._logger.warning(f"{tries}/{max_tries} {err} {method} {url}")
|
73
|
-
if tries >= max_tries:
|
74
|
-
raise err
|
75
|
-
await async_safe_sleep(timedelta(seconds=0.1).total_seconds())
|
76
|
-
continue
|
49
|
+
async def _async_make_http_request(
|
50
|
+
self, *, method: str = "GET", url: str, params: dict[str, Any] | None = None
|
51
|
+
) -> ClientResponse:
|
52
|
+
response = await async_make_http_request(
|
53
|
+
method=method,
|
54
|
+
url=url,
|
55
|
+
headers=self.headers,
|
56
|
+
params=params
|
57
|
+
)
|
58
|
+
response.raise_for_status()
|
59
|
+
return response
|
77
60
|
|
78
61
|
async def healthcheck(self) -> bool:
|
79
|
-
response = await self.
|
80
|
-
response.raise_for_status()
|
62
|
+
response = await self._async_make_http_request(method="GET", url=urljoin(self.base_url, "healthcheck"))
|
81
63
|
json_data = await response.json()
|
82
|
-
return json_data["data"]["healthcheck"]
|
64
|
+
return json_data["data"]["healthcheck"] == "healthcheck"
|
83
65
|
|
84
66
|
async def is_healthcheck_good(self) -> bool:
|
85
67
|
try:
|
86
68
|
return await self.healthcheck()
|
87
|
-
except
|
88
|
-
|
89
|
-
|
90
|
-
async def auth_healthcheck(self) -> bool:
|
91
|
-
response = await self._async_make_request(method="GET", url=urljoin(self.base_url, "auth_healthcheck"))
|
92
|
-
response.raise_for_status()
|
93
|
-
json_data = await response.json()
|
94
|
-
return json_data["data"]["auth_healthcheck"]
|
95
|
-
|
96
|
-
async def is_auth_healthcheck_good(self) -> bool:
|
97
|
-
try:
|
98
|
-
return await self.auth_healthcheck()
|
99
|
-
except ClientResponseError:
|
69
|
+
except Exception as exception:
|
70
|
+
self._logger.error(exception)
|
100
71
|
return False
|
101
72
|
|
102
73
|
async def generate_image_from_number(self, *, number: int) -> GenerateImageFromNumberResApiModel:
|
103
|
-
response = await self.
|
74
|
+
response = await self._async_make_http_request(
|
104
75
|
method="GET", url=urljoin(self.base_url, "generate_image_from_number"),
|
105
76
|
params={"number": number}
|
106
77
|
)
|
107
|
-
response.raise_for_status()
|
108
78
|
json_data = await response.json()
|
109
79
|
return GenerateImageFromNumberResApiModel.model_validate(json_data)
|
110
80
|
|
arpakitlib/ar_fastapi_util.py
CHANGED
@@ -579,7 +579,8 @@ def create_fastapi_app(
|
|
579
579
|
shutdown_api_events: list[BaseShutdownAPIEvent] | None = None,
|
580
580
|
transmitted_api_data: BaseTransmittedAPIData = BaseTransmittedAPIData(),
|
581
581
|
main_api_router: APIRouter = simple_api_router_for_testing(),
|
582
|
-
contact: dict[str, Any] | None = None
|
582
|
+
contact: dict[str, Any] | None = None,
|
583
|
+
media_dirpath: str | None = None
|
583
584
|
):
|
584
585
|
if contact is None:
|
585
586
|
contact = _DEFAULT_CONTACT
|
@@ -603,6 +604,9 @@ def create_fastapi_app(
|
|
603
604
|
contact=contact
|
604
605
|
)
|
605
606
|
|
607
|
+
if media_dirpath is not None:
|
608
|
+
app.mount("/media", StaticFiles(directory=media_dirpath), name="media")
|
609
|
+
|
606
610
|
app.state.transmitted_api_data = transmitted_api_data
|
607
611
|
|
608
612
|
add_cors_to_app(app=app)
|
@@ -76,11 +76,11 @@ class ScheduleUUSTAPIClient:
|
|
76
76
|
self,
|
77
77
|
*,
|
78
78
|
url: str,
|
79
|
-
params: dict | None = None
|
79
|
+
params: dict[str, Any] | None = None
|
80
80
|
) -> dict[str, Any]:
|
81
81
|
response = await async_make_http_request(
|
82
|
-
url=url,
|
83
82
|
method="GET",
|
83
|
+
url=url,
|
84
84
|
params=combine_dicts(params, self.auth_params()),
|
85
85
|
proxy_url_=self.api_proxy_url,
|
86
86
|
max_tries_=9,
|
@@ -65,7 +65,7 @@ arpakitlib/_arpakit_project_template/src/test_data/make_test_data_4.py,sha256=Wq
|
|
65
65
|
arpakitlib/_arpakit_project_template/src/test_data/make_test_data_5.py,sha256=ogTmetjQiRa57TKNfVH5A6GFTqBrU1Js0vTok6jlL_A,82
|
66
66
|
arpakitlib/_arpakit_project_template/src/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
67
67
|
arpakitlib/ar_additional_model_util.py,sha256=tNzZhZtvtJ1qC6Cn4UnyoEL58HudfpCdQy5ftkCqyik,473
|
68
|
-
arpakitlib/ar_aiogram_util.py,sha256=
|
68
|
+
arpakitlib/ar_aiogram_util.py,sha256=5JPCDZpdBGTE-EIWPRez9amCZAX7XemFIVu5YrQK7Pw,12264
|
69
69
|
arpakitlib/ar_arpakit_lib_module_util.py,sha256=V_mc3Ml73Tzz3arxmwEfIxruKMyrwbe8XZ9FfVDtUXY,5446
|
70
70
|
arpakitlib/ar_arpakit_schedule_uust_api_client_util.py,sha256=SYWWQDohPnw0qpBIu2hEvGZRVdaI4NUUQdEjnMnseo4,18237
|
71
71
|
arpakitlib/ar_arpakitlib_cli.py,sha256=T-YGAL6hRdrT2x3ug33N3GrWLYKSjK25r9SlaiBT7-M,2366
|
@@ -74,7 +74,7 @@ arpakitlib/ar_base_worker_util.py,sha256=YGoSpkE52QGu_mQdrefThc-pCnhhLEhWchSM3HZ
|
|
74
74
|
arpakitlib/ar_cache_file_util.py,sha256=Fo2pH-Zqm966KWFBHG_pbiySGZvhIFCYqy7k1weRfJ0,3476
|
75
75
|
arpakitlib/ar_datetime_util.py,sha256=Xe1NiT9oPQzNSG7RVRkhukhbg4i-hhS5ImmV7sPUc8o,971
|
76
76
|
arpakitlib/ar_dict_util.py,sha256=cF5LQJ6tLqyGoEXfDljMDZrikeZoWPw7CgINHIFGvXM,419
|
77
|
-
arpakitlib/ar_dream_ai_api_client_util.py,sha256=
|
77
|
+
arpakitlib/ar_dream_ai_api_client_util.py,sha256=CLN0RnuFn-JzoXLiz2eqnt-z2fkG6NbZEDLThVAyR88,2770
|
78
78
|
arpakitlib/ar_encrypt_decrypt_util.py,sha256=GhWnp7HHkbhwFVVCzO1H07m-5gryr4yjWsXjOaNQm1Y,520
|
79
79
|
arpakitlib/ar_enumeration_util.py,sha256=0DN46uyI0Gu9JPDgso3XPbnre7hZZefYTZwmmE1iYH4,2250
|
80
80
|
arpakitlib/ar_fastapi_static/redoc/redoc.standalone.js,sha256=WCuodUNv1qVh0oW5fjnJDwb5AwOue73jKHdI9z8iGKU,909365
|
@@ -96,7 +96,7 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
|
|
96
96
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
|
97
97
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
|
98
98
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
|
99
|
-
arpakitlib/ar_fastapi_util.py,sha256=
|
99
|
+
arpakitlib/ar_fastapi_util.py,sha256=X0kwP4b58gUhIkdXv8ougCGWbbIMB_6Qy-FMcd7mdk0,21744
|
100
100
|
arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
|
101
101
|
arpakitlib/ar_file_util.py,sha256=XiwmeycxoLqtYnGOu5q6IEaJJXilZvtLvsKDKtwqSLY,137
|
102
102
|
arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
|
@@ -117,7 +117,7 @@ arpakitlib/ar_parse_command.py,sha256=-s61xcATIsfw1eV_iD3xi-grsitbGzSDoAFc5V0OFy
|
|
117
117
|
arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJAdo,945
|
118
118
|
arpakitlib/ar_project_template_util.py,sha256=Yh3tzNYq0rrKc1MY-qsW1Ljhi9ADz8nYXMiPDH-e6PQ,3097
|
119
119
|
arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
|
120
|
-
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=
|
120
|
+
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=XLaXoKqZRUY-pbn9YAXwnyX7LElDYju_eSTbXHPnyEY,6037
|
121
121
|
arpakitlib/ar_settings_util.py,sha256=NvFzpIaQhlMp-BZwttUY_9gamMC5cpJk2Kp2B3BtMug,1296
|
122
122
|
arpakitlib/ar_sleep_util.py,sha256=9ZN4Qo4eZ_q3hjM7vNBQjFRcH-9-sqv3QLSjnxVJE90,1405
|
123
123
|
arpakitlib/ar_sqlalchemy_model_util.py,sha256=ttdgOwQfoHTKqgivBtXoSbJoBCASHDjLEFK5tJ9kNNE,4779
|
@@ -127,9 +127,9 @@ arpakitlib/ar_str_util.py,sha256=AhcdrEm-pXRilCaDWCdTfVkQSy0SnbE52ur43Ltr6cI,212
|
|
127
127
|
arpakitlib/ar_type_util.py,sha256=5nDnXL5Oyozlg8XvxMrogsoYiG8_atItg46A0mtv-pk,2025
|
128
128
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=5GMvu8paByni8buhc1vpHB7n6oXe0gPfj1LSvnyZCrQ,5307
|
129
129
|
arpakitlib/ar_zabbix_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
|
130
|
-
arpakitlib-1.6.
|
131
|
-
arpakitlib-1.6.
|
132
|
-
arpakitlib-1.6.
|
133
|
-
arpakitlib-1.6.
|
134
|
-
arpakitlib-1.6.
|
135
|
-
arpakitlib-1.6.
|
130
|
+
arpakitlib-1.6.92.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
131
|
+
arpakitlib-1.6.92.dist-info/METADATA,sha256=FZocXYl5hW3Jsx-yVBCzGlw36cXaS3il6QcsGbtcl8I,2739
|
132
|
+
arpakitlib-1.6.92.dist-info/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
|
133
|
+
arpakitlib-1.6.92.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
134
|
+
arpakitlib-1.6.92.dist-info/entry_points.txt,sha256=VHkTDXDOMrgcNzGfKhEhoOIIz6T8Kkt46hy95Zc1iL0,74
|
135
|
+
arpakitlib-1.6.92.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|