arpakitlib 1.6.46__py3-none-any.whl → 1.7.89__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.
Files changed (158) hide show
  1. arpakitlib/_arpakit_project_template/.gitignore +51 -0
  2. arpakitlib/_arpakit_project_template/.python-version +1 -0
  3. arpakitlib/_arpakit_project_template/ARPAKITLIB +1 -0
  4. arpakitlib/_arpakit_project_template/AUTHOR.md +4 -0
  5. arpakitlib/{LICENSE → _arpakit_project_template/LICENSE} +1 -1
  6. arpakitlib/_arpakit_project_template/NOTICE +16 -0
  7. arpakitlib/_arpakit_project_template/README.md +6 -0
  8. arpakitlib/_arpakit_project_template/example.env +22 -0
  9. arpakitlib/_arpakit_project_template/manage/__init__.py +0 -0
  10. arpakitlib/_arpakit_project_template/manage/docker_ps.sh +2 -0
  11. arpakitlib/_arpakit_project_template/manage/docker_ps_a.sh +2 -0
  12. arpakitlib/_arpakit_project_template/manage/docker_run_postgres_for_dev.sh +4 -0
  13. arpakitlib/_arpakit_project_template/manage/docker_start_postgres_for_dev.sh +2 -0
  14. arpakitlib/_arpakit_project_template/manage/docker_stop_postgres_for_dev.sh +2 -0
  15. arpakitlib/_arpakit_project_template/manage/example_nginx_proxy.nginx +14 -0
  16. arpakitlib/_arpakit_project_template/manage/example_poetry_arpakitlib.sh +1 -0
  17. arpakitlib/_arpakit_project_template/manage/example_pyproject.toml +18 -0
  18. arpakitlib/_arpakit_project_template/manage/example_systemd.service +12 -0
  19. arpakitlib/_arpakit_project_template/manage/git_branch.sh +2 -0
  20. arpakitlib/_arpakit_project_template/manage/git_commit.sh +3 -0
  21. arpakitlib/_arpakit_project_template/manage/git_push_arpakit_company_github_1.sh +4 -0
  22. arpakitlib/_arpakit_project_template/manage/git_push_arpakit_company_gitlab_1.sh +4 -0
  23. arpakitlib/_arpakit_project_template/manage/git_push_arpakit_github_1.sh +4 -0
  24. arpakitlib/_arpakit_project_template/manage/git_push_arpakit_gitlab_1.sh +4 -0
  25. arpakitlib/_arpakit_project_template/manage/git_remote_v.sh +2 -0
  26. arpakitlib/_arpakit_project_template/manage/git_set_arpakit_company_origin.sh +7 -0
  27. arpakitlib/_arpakit_project_template/manage/git_set_arpakit_origin.sh +7 -0
  28. arpakitlib/_arpakit_project_template/manage/git_status.sh +2 -0
  29. arpakitlib/_arpakit_project_template/manage/hello_world.py +6 -0
  30. arpakitlib/_arpakit_project_template/manage/json_beutify.py +10 -0
  31. arpakitlib/_arpakit_project_template/manage/logging_check.py +14 -0
  32. arpakitlib/_arpakit_project_template/manage/note/__init__.py +0 -0
  33. arpakitlib/_arpakit_project_template/manage/note/note_1.txt +0 -0
  34. arpakitlib/_arpakit_project_template/manage/note/note_2.txt +0 -0
  35. arpakitlib/_arpakit_project_template/manage/note/note_3.txt +0 -0
  36. arpakitlib/_arpakit_project_template/manage/note/note_4.txt +0 -0
  37. arpakitlib/_arpakit_project_template/manage/note/note_5.txt +0 -0
  38. arpakitlib/_arpakit_project_template/manage/poetry_add_plugin_export.sh +2 -0
  39. arpakitlib/_arpakit_project_template/manage/poetry_check.sh +2 -0
  40. arpakitlib/_arpakit_project_template/manage/poetry_clear_cache.sh +4 -0
  41. arpakitlib/_arpakit_project_template/manage/poetry_config_virtualenvs_in_project_true.sh +2 -0
  42. arpakitlib/_arpakit_project_template/manage/poetry_generate_requirements.txt.sh +1 -0
  43. arpakitlib/_arpakit_project_template/manage/poetry_install.sh +5 -0
  44. arpakitlib/_arpakit_project_template/manage/poetry_lock.sh +2 -0
  45. arpakitlib/_arpakit_project_template/manage/poetry_remove_and_add_arpakitlib.sh +7 -0
  46. arpakitlib/_arpakit_project_template/manage/poetry_show.sh +2 -0
  47. arpakitlib/_arpakit_project_template/manage/poetry_show_arpakitlib.sh +2 -0
  48. arpakitlib/_arpakit_project_template/manage/poetry_update.sh +6 -0
  49. arpakitlib/_arpakit_project_template/manage/poetry_update_arpakitlib.sh +5 -0
  50. arpakitlib/_arpakit_project_template/manage/requirements.txt +209 -0
  51. arpakitlib/_arpakit_project_template/manage/sandbox/__init__.py +0 -0
  52. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_1.py +14 -0
  53. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_2.py +14 -0
  54. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_3.py +14 -0
  55. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_4.py +14 -0
  56. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_5.py +14 -0
  57. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_6.py +14 -0
  58. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_7.py +14 -0
  59. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_8.sh +0 -0
  60. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_9.sh +0 -0
  61. arpakitlib/_arpakit_project_template/manage/settings_check.py +10 -0
  62. arpakitlib/_arpakit_project_template/manage/settings_generate_env_example.py +13 -0
  63. arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_check_conn.py +11 -0
  64. arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_init.py +11 -0
  65. arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_reinit.py +11 -0
  66. arpakitlib/_arpakit_project_template/resource/__init__.py +0 -0
  67. arpakitlib/_arpakit_project_template/resource/static/__init__.py +0 -0
  68. arpakitlib/_arpakit_project_template/resource/static/healthcheck +1 -0
  69. arpakitlib/_arpakit_project_template/resource/static/helloworld +1 -0
  70. arpakitlib/_arpakit_project_template/src/__init__.py +0 -0
  71. arpakitlib/_arpakit_project_template/src/additional_model/__init__.py +0 -0
  72. arpakitlib/_arpakit_project_template/src/additional_model/additional_model.py +6 -0
  73. arpakitlib/_arpakit_project_template/src/api/__init__.py +0 -0
  74. arpakitlib/_arpakit_project_template/src/api/asgi.py +3 -0
  75. arpakitlib/_arpakit_project_template/src/api/auth.py +1 -0
  76. arpakitlib/_arpakit_project_template/src/api/const.py +13 -0
  77. arpakitlib/_arpakit_project_template/src/api/create_api_app.py +117 -0
  78. arpakitlib/_arpakit_project_template/src/api/event.py +20 -0
  79. arpakitlib/_arpakit_project_template/src/api/router/__init__.py +0 -0
  80. arpakitlib/_arpakit_project_template/src/api/router/main_router.py +9 -0
  81. arpakitlib/_arpakit_project_template/src/api/router/v1/__init__.py +0 -0
  82. arpakitlib/_arpakit_project_template/src/api/router/v1/get_api_error_info.py +27 -0
  83. arpakitlib/_arpakit_project_template/src/api/router/v1/main_router.py +11 -0
  84. arpakitlib/_arpakit_project_template/src/api/schema/__init__.py +0 -0
  85. arpakitlib/_arpakit_project_template/src/api/schema/v1/__init__.py +0 -0
  86. arpakitlib/_arpakit_project_template/src/api/schema/v1/in_.py +0 -0
  87. arpakitlib/_arpakit_project_template/src/api/schema/v1/out.py +6 -0
  88. arpakitlib/_arpakit_project_template/src/api/start_api_for_dev.py +17 -0
  89. arpakitlib/_arpakit_project_template/src/api/start_api_for_dev_with_reload.py +9 -0
  90. arpakitlib/_arpakit_project_template/src/api/transmitted_api_data.py +9 -0
  91. arpakitlib/_arpakit_project_template/src/api/util.py +0 -0
  92. arpakitlib/_arpakit_project_template/src/business_service/__init__.py +0 -0
  93. arpakitlib/_arpakit_project_template/src/core/__init__.py +0 -0
  94. arpakitlib/_arpakit_project_template/src/core/const.py +48 -0
  95. arpakitlib/_arpakit_project_template/src/core/settings.py +86 -0
  96. arpakitlib/_arpakit_project_template/src/core/util.py +58 -0
  97. arpakitlib/_arpakit_project_template/src/db/__init__.py +0 -0
  98. arpakitlib/_arpakit_project_template/src/db/sqlalchemy_model.py +8 -0
  99. arpakitlib/_arpakit_project_template/src/db/util.py +21 -0
  100. arpakitlib/_arpakit_project_template/src/operation_execution/__init__.py +0 -0
  101. arpakitlib/_arpakit_project_template/src/operation_execution/const.py +9 -0
  102. arpakitlib/_arpakit_project_template/src/operation_execution/operation_executor.py +14 -0
  103. arpakitlib/_arpakit_project_template/src/operation_execution/scheduled_operations.py +25 -0
  104. arpakitlib/_arpakit_project_template/src/operation_execution/start_operation_executor_worker_for_dev.py +18 -0
  105. arpakitlib/_arpakit_project_template/src/operation_execution/start_scheduled_operation_creator_worker_for_dev.py +17 -0
  106. arpakitlib/_arpakit_project_template/src/operation_execution/util.py +21 -0
  107. arpakitlib/_arpakit_project_template/src/test_data/__init__.py +0 -0
  108. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_1.py +6 -0
  109. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_2.py +6 -0
  110. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_3.py +6 -0
  111. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_4.py +6 -0
  112. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_5.py +6 -0
  113. arpakitlib/_arpakit_project_template/src/util/__init__.py +0 -0
  114. arpakitlib/api_key_util.py +21 -0
  115. arpakitlib/ar_additional_model_util.py +25 -2
  116. arpakitlib/ar_aiogram_util.py +10 -18
  117. arpakitlib/ar_arpakit_lib_module_util.py +6 -1
  118. arpakitlib/ar_arpakit_project_template_util.py +96 -0
  119. arpakitlib/ar_arpakit_schedule_uust_api_client_util.py +24 -3
  120. arpakitlib/ar_arpakitlib_cli_util.py +79 -0
  121. arpakitlib/ar_base_worker_util.py +95 -48
  122. arpakitlib/ar_dream_ai_api_client_util.py +26 -52
  123. arpakitlib/ar_enumeration_util.py +11 -0
  124. arpakitlib/ar_exception_util.py +18 -0
  125. arpakitlib/ar_fastapi_static/healthcheck +1 -0
  126. arpakitlib/ar_fastapi_util.py +270 -137
  127. arpakitlib/ar_file_util.py +22 -0
  128. arpakitlib/ar_func_util.py +55 -0
  129. arpakitlib/ar_http_request_util.py +35 -6
  130. arpakitlib/ar_json_util.py +13 -7
  131. arpakitlib/ar_logging_util.py +5 -2
  132. arpakitlib/ar_need_type_util.py +12 -2
  133. arpakitlib/{ar_openai_util.py → ar_openai_api_client_util.py} +16 -2
  134. arpakitlib/ar_operation_execution_util.py +250 -105
  135. arpakitlib/ar_parse_command.py +25 -7
  136. arpakitlib/ar_schedule_uust_api_client_util.py +37 -23
  137. arpakitlib/ar_settings_util.py +37 -11
  138. arpakitlib/ar_sleep_util.py +0 -13
  139. arpakitlib/ar_sqlalchemy_model_util.py +35 -10
  140. arpakitlib/ar_sqlalchemy_util.py +4 -3
  141. arpakitlib/{ar_ssh_util.py → ar_ssh_runner_util.py} +2 -2
  142. arpakitlib/ar_str_util.py +43 -2
  143. arpakitlib/ar_type_util.py +68 -4
  144. arpakitlib/ar_yookassa_api_client_util.py +26 -44
  145. {arpakitlib-1.6.46.dist-info → arpakitlib-1.7.89.dist-info}/LICENSE +1 -1
  146. {arpakitlib-1.6.46.dist-info → arpakitlib-1.7.89.dist-info}/METADATA +17 -8
  147. arpakitlib-1.7.89.dist-info/NOTICE +16 -0
  148. arpakitlib-1.7.89.dist-info/RECORD +186 -0
  149. arpakitlib-1.7.89.dist-info/entry_points.txt +3 -0
  150. arpakitlib/AUTHOR.md +0 -7
  151. arpakitlib/NOTICE +0 -2
  152. arpakitlib/README.md +0 -7
  153. arpakitlib/ar_arpakitlib_info.py +0 -13
  154. arpakitlib/ar_generate_env_example.py +0 -22
  155. arpakitlib-1.6.46.dist-info/NOTICE +0 -2
  156. arpakitlib-1.6.46.dist-info/RECORD +0 -71
  157. /arpakitlib/{ar_zabbix_util.py → ar_zabbix_api_client_util.py} +0 -0
  158. {arpakitlib-1.6.46.dist-info → arpakitlib-1.7.89.dist-info}/WHEEL +0 -0
@@ -0,0 +1,21 @@
1
+ import importlib
2
+ from contextlib import suppress
3
+ from functools import lru_cache
4
+
5
+ from arpakitlib.ar_sqlalchemy_util import SQLAlchemyDB
6
+ from src.core.settings import get_cached_settings
7
+
8
+
9
+ def create_sqlalchemy_db() -> SQLAlchemyDB:
10
+ with suppress(Exception):
11
+ importlib.import_module("src.db.sqlalchemy_model")
12
+
13
+ return SQLAlchemyDB(
14
+ db_url=get_cached_settings().sql_db_url,
15
+ db_echo=get_cached_settings().sql_db_echo
16
+ )
17
+
18
+
19
+ @lru_cache()
20
+ def get_cached_sqlalchemy_db() -> SQLAlchemyDB:
21
+ return create_sqlalchemy_db()
@@ -0,0 +1,9 @@
1
+ from arpakitlib.ar_sqlalchemy_model_util import BaseOperationTypes
2
+
3
+
4
+ class OperationTypes(BaseOperationTypes):
5
+ pass
6
+
7
+
8
+ if __name__ == '__main__':
9
+ OperationTypes.print()
@@ -0,0 +1,14 @@
1
+ from arpakitlib.ar_operation_execution_util import BaseOperationExecutor
2
+ from arpakitlib.ar_sqlalchemy_model_util import OperationDBM
3
+
4
+
5
+ class OperationExecutor(BaseOperationExecutor):
6
+ def sync_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
7
+ # ...
8
+ operation_dbm = super().sync_execute_operation(operation_dbm=operation_dbm)
9
+ return operation_dbm
10
+
11
+ async def async_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
12
+ # ...
13
+ operation_dbm = await super().async_execute_operation(operation_dbm=operation_dbm)
14
+ return operation_dbm
@@ -0,0 +1,25 @@
1
+ from datetime import timedelta, time
2
+
3
+ from arpakitlib.ar_operation_execution_util import ScheduledOperation, every_timedelta_is_time_func, \
4
+ between_different_times_is_time_func
5
+ from arpakitlib.ar_sqlalchemy_model_util import BaseOperationTypes
6
+
7
+ ALL_SCHEDULED_OPERATIONS = []
8
+
9
+ healthcheck_1_scheduled_operation = ScheduledOperation(
10
+ type=BaseOperationTypes.healthcheck_,
11
+ input_data={"healthcheck_1": "healthcheck_1"},
12
+ is_time_func=every_timedelta_is_time_func(td=timedelta(seconds=15))
13
+ )
14
+ ALL_SCHEDULED_OPERATIONS.append(healthcheck_1_scheduled_operation)
15
+
16
+ healthcheck_2_scheduled_operation = ScheduledOperation(
17
+ type=BaseOperationTypes.healthcheck_,
18
+ input_data={"healthcheck_2": "healthcheck_2"},
19
+ is_time_func=between_different_times_is_time_func(
20
+ from_time=time(hour=12, minute=0),
21
+ to_time=time(hour=12, minute=15)
22
+ ),
23
+ timeout_after_creation=timedelta(seconds=60)
24
+ )
25
+ ALL_SCHEDULED_OPERATIONS.append(healthcheck_2_scheduled_operation)
@@ -0,0 +1,18 @@
1
+ from arpakitlib.ar_operation_execution_util import OperationExecutorWorker
2
+ from src.core.util import setup_logging
3
+ from src.db.util import get_cached_sqlalchemy_db
4
+ from src.operation_execution.operation_executor import OperationExecutor
5
+
6
+
7
+ def start_operation_executor_worker_for_dev():
8
+ setup_logging()
9
+ worker = OperationExecutorWorker(
10
+ sqlalchemy_db=get_cached_sqlalchemy_db(),
11
+ operation_executor=OperationExecutor(sqlalchemy_db=get_cached_sqlalchemy_db()),
12
+ filter_operation_types=None
13
+ )
14
+ worker.sync_safe_run()
15
+
16
+
17
+ if __name__ == '__main__':
18
+ start_operation_executor_worker_for_dev()
@@ -0,0 +1,17 @@
1
+ from arpakitlib.ar_operation_execution_util import ScheduledOperationCreatorWorker
2
+ from src.core.util import setup_logging
3
+ from src.db.util import get_cached_sqlalchemy_db
4
+ from src.operation_execution.scheduled_operations import ALL_SCHEDULED_OPERATIONS
5
+
6
+
7
+ def start_create_scheduled_operation_worker_for_dev():
8
+ setup_logging()
9
+ worker = ScheduledOperationCreatorWorker(
10
+ sqlalchemy_db=get_cached_sqlalchemy_db(),
11
+ scheduled_operations=ALL_SCHEDULED_OPERATIONS
12
+ )
13
+ worker.sync_safe_run()
14
+
15
+
16
+ if __name__ == '__main__':
17
+ start_create_scheduled_operation_worker_for_dev()
@@ -0,0 +1,21 @@
1
+ from datetime import timedelta
2
+ from functools import lru_cache
3
+
4
+ from arpakitlib.ar_operation_execution_util import ScheduledOperationCreatorWorker
5
+ from src.db.util import get_cached_sqlalchemy_db
6
+
7
+
8
+ def create_scheduled_operation_creator_worker() -> ScheduledOperationCreatorWorker:
9
+ from src.operation_execution.scheduled_operations import ALL_SCHEDULED_OPERATIONS
10
+ scheduled_operation_creator_worker = ScheduledOperationCreatorWorker(
11
+ sqlalchemy_db=get_cached_sqlalchemy_db(),
12
+ scheduled_operations=ALL_SCHEDULED_OPERATIONS,
13
+ timeout_after_run=timedelta(seconds=0.1).total_seconds(),
14
+ timeout_after_err_in_run=timedelta(seconds=1).total_seconds()
15
+ )
16
+ return scheduled_operation_creator_worker
17
+
18
+
19
+ @lru_cache()
20
+ def get_scheduled_operation_creator_worker() -> ScheduledOperationCreatorWorker:
21
+ return create_scheduled_operation_creator_worker()
@@ -0,0 +1,6 @@
1
+ def make_test_data_1():
2
+ pass
3
+
4
+
5
+ async def async_make_test_data_1():
6
+ pass
@@ -0,0 +1,6 @@
1
+ def make_test_data_2():
2
+ pass
3
+
4
+
5
+ async def async_make_test_data_2():
6
+ pass
@@ -0,0 +1,6 @@
1
+ def make_test_data_3():
2
+ pass
3
+
4
+
5
+ async def async_make_test_data_3():
6
+ pass
@@ -0,0 +1,6 @@
1
+ def make_test_data_4():
2
+ pass
3
+
4
+
5
+ async def async_make_test_data_4():
6
+ pass
@@ -0,0 +1,6 @@
1
+ def make_test_data_5():
2
+ pass
3
+
4
+
5
+ async def async_make_test_data_5():
6
+ pass
@@ -0,0 +1,21 @@
1
+ from uuid import uuid4
2
+
3
+ from arpakitlib.ar_datetime_util import now_utc_dt
4
+
5
+ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
6
+
7
+
8
+ def generate_api_key() -> str:
9
+ return (
10
+ f"apikey{str(uuid4()).replace('-', '')}{str(now_utc_dt().timestamp()).replace('.', '')}"
11
+ )
12
+
13
+
14
+ def __example():
15
+ for i in range(5):
16
+ api_key = generate_api_key()
17
+ print(f"API-key: {api_key}")
18
+
19
+
20
+ if __name__ == '__main__':
21
+ __example()
@@ -3,14 +3,37 @@ from typing import Any
3
3
 
4
4
  from pydantic import BaseModel, ConfigDict
5
5
 
6
+ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
7
+
6
8
 
7
9
  class BaseAM(BaseModel):
8
10
  model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
9
- bus_data: dict[str, Any] = {}
11
+ _bus_data: dict[str, Any] | None = None
12
+
13
+ @property
14
+ def bus_data(self) -> dict[str, Any]:
15
+ if self._bus_data is None:
16
+ self._bus_data = {}
17
+ return self._bus_data
10
18
 
11
19
 
12
20
  def __example():
13
- pass
21
+ class UserAM(BaseAM):
22
+ id: int
23
+ name: str
24
+ email: str
25
+
26
+ @property
27
+ def bus_data_age(self) -> int | None:
28
+ return self.bus_data.get("age")
29
+
30
+ user = UserAM(id=1, name="John Doe", email="john.doe@example.com")
31
+ print(user.name) # John Doe
32
+
33
+ # bus_data
34
+ user.bus_data["age"] = 22
35
+ print(user.bus_data) # {'age': '22'}
36
+ print(user.bus_data_age) # 22
14
37
 
15
38
 
16
39
  if __name__ == '__main__':
@@ -16,8 +16,6 @@ from pydantic import BaseModel, ConfigDict
16
16
 
17
17
  from arpakitlib.ar_need_type_util import parse_need_type, NeedTypes
18
18
  from arpakitlib.ar_parse_command import BadCommandFormat, parse_command
19
- from arpakitlib.ar_settings_util import SimpleSettings
20
- from arpakitlib.ar_sqlalchemy_util import SQLAlchemyDB
21
19
  from arpakitlib.ar_type_util import raise_for_types, raise_for_type
22
20
 
23
21
  _ARPAKIT_LIB_MODULE_VERSION = "3.0"
@@ -293,7 +291,7 @@ def as_tg_command(
293
291
  f"Value (key={_param.key}, index={_param.index}) is required"
294
292
  )
295
293
  else:
296
- value = parse_need_type(value=value, need_type=_param.need_type)
294
+ value = parse_need_type(value=value, need_type=_param.need_type, allow_none=False)
297
295
 
298
296
  kwargs[_param.key] = value
299
297
 
@@ -327,27 +325,21 @@ class SimpleMiddleware(BaseMiddleware, ABC):
327
325
  class BaseTransmittedTgBotData(BaseModel):
328
326
  model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True, from_attributes=True)
329
327
 
330
- tg_bot: Bot
331
- settings: SimpleSettings | None = None
332
328
 
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
333
331
 
334
- class SimpleTransmittedTgBotData(BaseTransmittedTgBotData):
335
- sqlalchemy_db: SQLAlchemyDB | None = None
336
-
337
-
338
- def create_aiogram_tg_bot(*, tg_bot_token: str, tg_bot_proxy_url: str | None = None) -> Bot:
339
- session: AiohttpSession | None = None
340
332
  if tg_bot_proxy_url:
341
- session = AiohttpSession(proxy=tg_bot_proxy_url)
342
- tg_bot = Bot(
343
- token=tg_bot_token,
344
- default=DefaultBotProperties(
333
+ kwargs["session"] = AiohttpSession(proxy=tg_bot_proxy_url)
334
+
335
+ if kwargs.get("default") is None:
336
+ kwargs["default"] = DefaultBotProperties(
345
337
  parse_mode=ParseMode.HTML,
346
338
  disable_notification=False,
347
339
  link_preview_is_disabled=True
348
- ),
349
- session=session
350
- )
340
+ )
341
+
342
+ tg_bot = Bot(**kwargs)
351
343
 
352
344
  return tg_bot
353
345
 
@@ -144,7 +144,12 @@ def get_arpakit_lib_modules() -> ArpakitLibModules:
144
144
 
145
145
 
146
146
  def __example():
147
- pass
147
+ for module_name, d in (
148
+ get_arpakit_lib_modules().module_name_to_module_version_and_module_has_errors().items()
149
+ ):
150
+ print(module_name)
151
+ print(d)
152
+ print()
148
153
 
149
154
 
150
155
  if __name__ == '__main__':
@@ -0,0 +1,96 @@
1
+ # arpakit
2
+
3
+ import logging
4
+ import os
5
+
6
+ from arpakitlib.ar_str_util import make_none_if_blank, raise_if_string_blank
7
+ from arpakitlib.ar_type_util import raise_for_type
8
+
9
+ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
10
+
11
+ _logger = logging.getLogger(__name__)
12
+
13
+
14
+ def init_arpakit_project_template(
15
+ *,
16
+ project_dirpath: str = "./",
17
+ overwrite_if_exists: bool = False,
18
+ project_name: str | None = None,
19
+ sql_db_port: int | None = None,
20
+ api_port: int | None = None,
21
+ ignore_paths_startswith: list[str] | str | None = None,
22
+ only_paths_startswith: list[str] | str | None = None,
23
+ ):
24
+ raise_if_string_blank(project_dirpath)
25
+
26
+ if project_name:
27
+ project_name = project_name.strip()
28
+ project_name = make_none_if_blank(project_name)
29
+
30
+ if sql_db_port is not None:
31
+ raise_for_type(sql_db_port, int)
32
+
33
+ if api_port is not None:
34
+ raise_for_type(api_port, int)
35
+
36
+ if isinstance(ignore_paths_startswith, str):
37
+ ignore_paths_startswith = [ignore_paths_startswith]
38
+ if ignore_paths_startswith is None:
39
+ ignore_paths_startswith = []
40
+
41
+ if isinstance(only_paths_startswith, str):
42
+ only_paths_startswith = [only_paths_startswith]
43
+ if only_paths_startswith is None:
44
+ only_paths_startswith = []
45
+
46
+ def _generate_filepath_to_content() -> dict[str, str]:
47
+ arpakit_project_template_dirpath = os.path.join(
48
+ os.path.dirname(os.path.abspath(__file__)), "_arpakit_project_template"
49
+ )
50
+ res = {}
51
+ for root, dirs, files in os.walk(arpakit_project_template_dirpath):
52
+ dirs[:] = [d for d in dirs if d != '__pycache__']
53
+ for file in files:
54
+ rel_path = os.path.relpath(os.path.join(root, file), arpakit_project_template_dirpath)
55
+ if (
56
+ ignore_paths_startswith
57
+ and
58
+ any(rel_path.startswith(ignore_path) for ignore_path in ignore_paths_startswith)
59
+ ):
60
+ _logger.info(f"ignoring file: {rel_path}")
61
+ continue
62
+ if (
63
+ only_paths_startswith
64
+ and
65
+ not any(rel_path.startswith(only_path) for only_path in only_paths_startswith)
66
+ ):
67
+ _logger.info(f"ignoring file: {rel_path}")
68
+ continue
69
+ with open(os.path.join(root, file), "r", encoding="utf-8") as _file:
70
+ _content = _file.read()
71
+ if project_name is not None:
72
+ _content = _content.replace("{PROJECT_NAME}", project_name)
73
+ if sql_db_port is not None:
74
+ _content = _content.replace("{SQL_DB_PORT}", str(sql_db_port))
75
+ if api_port is not None:
76
+ _content = _content.replace("{API_PORT}", str(api_port))
77
+ res[rel_path] = _content
78
+ return res
79
+
80
+ filepath_to_content = _generate_filepath_to_content()
81
+
82
+ if not os.path.exists(project_dirpath):
83
+ os.makedirs(project_dirpath)
84
+
85
+ for filepath, content in filepath_to_content.items():
86
+ full_filepath = os.path.join(project_dirpath, filepath)
87
+
88
+ if os.path.exists(full_filepath) and not overwrite_if_exists:
89
+ _logger.info(f"file exists and overwrite_if_exists is False, skipping: {full_filepath}")
90
+ continue
91
+
92
+ _logger.info(f"creating file: {full_filepath}")
93
+ os.makedirs(os.path.dirname(full_filepath), exist_ok=True)
94
+ with open(full_filepath, "w", encoding="utf-8") as file_:
95
+ file_.write(content)
96
+ _logger.info(f"file created: {full_filepath}")
@@ -17,7 +17,7 @@ from pydantic import ConfigDict, BaseModel
17
17
 
18
18
  from arpakitlib.ar_dict_util import combine_dicts
19
19
  from arpakitlib.ar_enumeration_util import Enumeration
20
- from arpakitlib.ar_json_util import safely_transfer_to_json_str
20
+ from arpakitlib.ar_json_util import safely_transfer_obj_to_json_str
21
21
  from arpakitlib.ar_sleep_util import async_safe_sleep
22
22
  from arpakitlib.ar_type_util import raise_for_type
23
23
 
@@ -53,7 +53,7 @@ class BaseAPIModel(BaseModel):
53
53
  model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
54
54
 
55
55
  def simple_json(self) -> str:
56
- return safely_transfer_to_json_str(self.model_dump(mode="json"))
56
+ return safely_transfer_obj_to_json_str(self.model_dump(mode="json"))
57
57
 
58
58
 
59
59
  class GroupAPIModel(BaseAPIModel):
@@ -521,7 +521,28 @@ def __example():
521
521
 
522
522
 
523
523
  async def __async_example():
524
- pass
524
+ client = ARPAKITScheduleUUSTAPIClient(api_key="TEST_API_KEY", use_cache=True)
525
+
526
+ healthcheck = await client.healthcheck()
527
+ print(f"Healthcheck: {healthcheck}")
528
+
529
+ auth_healthcheck = await client.auth_healthcheck()
530
+ print(f"Auth Healthcheck: {auth_healthcheck}")
531
+
532
+ current_week = await client.get_current_week()
533
+ print(f"Текущая неделя: {current_week.simple_json() if current_week else 'Не найдено'}")
534
+
535
+ current_semester = await client.get_current_semester()
536
+ print(f"Текущий семестр: {current_semester.simple_json() if current_semester else 'Не найдено'}")
537
+
538
+ groups = await client.get_groups()
539
+ print(f"Группы: {[group.simple_json() for group in groups]}")
540
+
541
+ teachers = await client.get_teachers()
542
+ print(f"Преподаватели: {[teacher.simple_json() for teacher in teachers]}")
543
+
544
+ weather = await client.get_weather_in_ufa()
545
+ print(f"Погода в Уфе: {weather.simple_json()}")
525
546
 
526
547
 
527
548
  if __name__ == '__main__':
@@ -0,0 +1,79 @@
1
+ # arpakit
2
+
3
+ import sys
4
+
5
+ from arpakitlib.ar_arpakit_project_template_util import init_arpakit_project_template
6
+ from arpakitlib.ar_need_type_util import parse_need_type, NeedTypes
7
+ from arpakitlib.ar_parse_command import parse_command
8
+ from arpakitlib.ar_str_util import raise_if_string_blank
9
+
10
+ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
11
+
12
+
13
+ def execute_arpakitlib_cli(*, full_command: str | None = None):
14
+ if full_command is None:
15
+ full_command = " ".join(sys.argv)
16
+
17
+ parsed_command = parse_command(text=full_command)
18
+ parsed_command.raise_for_command(needed_command="arpakitlib", lower_=True)
19
+
20
+ command = parsed_command.get_value_by_keys(keys=["command", "c"])
21
+ if command:
22
+ command = command.strip()
23
+ if not command:
24
+ raise Exception(f"not command, command={command}")
25
+
26
+ if command == "help":
27
+ print("Commands:")
28
+ print()
29
+ print("-c init_arpakit_project_template")
30
+ print("-project_dirpath ...")
31
+ print("-overwrite_if_exists ...")
32
+ print("-project_name ...")
33
+ print("-sql_db_port ...")
34
+ print("-api_port ...")
35
+ print("-ignore_paths_startswith ...")
36
+ print("-only_paths_startswith ...")
37
+ print("\n")
38
+
39
+ elif command == "init_arpakit_project_template":
40
+ project_dirpath = raise_if_string_blank(parsed_command.get_value_by_keys(keys=["pd", "project_dirpath"]))
41
+ overwrite_if_exists: bool = parse_need_type(
42
+ value=parsed_command.get_value_by_keys(keys=["oie", "overwrite_if_exists"]),
43
+ need_type=NeedTypes.bool_,
44
+ allow_none=False
45
+ )
46
+ project_name: str = parsed_command.get_value_by_keys(keys=["pm", "project_name"])
47
+ project_name = project_name.strip() if project_name.strip() else None
48
+ sql_db_port: int | None = parse_need_type(
49
+ value=parsed_command.get_value_by_keys(keys=["sdp", "sql_db_port"]),
50
+ need_type=NeedTypes.int_,
51
+ allow_none=True
52
+ )
53
+ api_port: int | None = parse_need_type(
54
+ value=parsed_command.get_value_by_keys(keys=["ap", "api_port"]),
55
+ need_type=NeedTypes.int_,
56
+ allow_none=True
57
+ )
58
+ ignore_paths_startswith: list[str] | None = parse_need_type(
59
+ value=parsed_command.get_value_by_keys(keys=["ipsw", "ignore_paths_startswith"]),
60
+ need_type=NeedTypes.list_of_str,
61
+ allow_none=True
62
+ )
63
+ only_paths_startswith: list[str] | None = parse_need_type(
64
+ value=parsed_command.get_value_by_keys(keys=["ops", "only_paths_startswith"]),
65
+ need_type=NeedTypes.list_of_str,
66
+ allow_none=True
67
+ )
68
+ init_arpakit_project_template(
69
+ project_dirpath=project_dirpath, overwrite_if_exists=overwrite_if_exists,
70
+ project_name=project_name, sql_db_port=sql_db_port, api_port=api_port,
71
+ ignore_paths_startswith=ignore_paths_startswith, only_paths_startswith=only_paths_startswith
72
+ )
73
+
74
+ else:
75
+ raise Exception(f"not recognized command, command={command}")
76
+
77
+
78
+ if __name__ == '__main__':
79
+ execute_arpakitlib_cli(full_command="/arpakitlib -c help")