From abe0cbb17318c0093be1edf41ba7c0950ac077b1 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Mon, 21 Apr 2025 13:50:51 +0200 Subject: [PATCH] New structure --- src/{ => applications/common}/domain/auth.py | 0 .../common}/domain/streamers.py | 7 +++ src/{ => applications/common}/domain/users.py | 0 .../common}/repositories/base.py | 0 .../common}/repositories/streamers.py | 0 .../common}/repositories/users.py | 6 +-- .../games_list/__init__.py | 0 .../games_list/discord.py | 0 .../games_list/games_list.py | 0 .../scheduler_sync/__init__.py | 0 .../scheduler_sync/comparators.py | 0 .../scheduler_sync/discord_events.py | 0 .../scheduler_sync/synchronizer.py | 0 .../scheduler_sync/tasks.py | 0 .../scheduler_sync/twitch_events.py | 0 .../stream_notifications/__init__.py | 0 .../stream_notifications/messages_proc.py | 0 .../stream_notifications/notification.py | 0 .../stream_notifications/reward_redemption.py | 0 .../sent_notifications.py | 0 .../stream_notifications/state.py | 0 .../stream_notifications/tasks.py | 0 .../stream_notifications/twitch/authorize.py | 0 .../twitch/token_storage.py | 0 .../stream_notifications/twitch/webhook.py | 0 .../stream_notifications/watcher.py | 0 .../web_app/__init__.py | 0 src/{modules => applications}/web_app/app.py | 0 .../web_app/auth/authx.py | 0 .../web_app/frontend/index.css | 0 .../web_app/frontend/index.html | 0 .../web_app/frontend/index.js | 0 .../web_app/serializers/auth.py | 0 .../web_app/serializers/streamer.py | 0 .../oauth/authorization_url_getter.py | 0 .../services/oauth/process_callback.py | 0 .../services/oauth/providers/__init__.py | 0 .../services/oauth/providers/getter.py | 0 .../services/oauth/providers/twitch.py | 0 .../web_app/utils/static.py | 0 .../web_app/views/__init__.py | 0 .../web_app/views/auth.py | 0 .../web_app/views/streamer.py | 0 src/main.py | 45 ------------------- src/modules/tasks.py | 2 - 45 files changed, 10 insertions(+), 50 deletions(-) rename src/{ => applications/common}/domain/auth.py (100%) rename src/{ => applications/common}/domain/streamers.py (99%) rename src/{ => applications/common}/domain/users.py (100%) rename src/{ => applications/common}/repositories/base.py (100%) rename src/{ => applications/common}/repositories/streamers.py (100%) rename src/{ => applications/common}/repositories/users.py (85%) rename src/{modules => applications}/games_list/__init__.py (100%) rename src/{modules => applications}/games_list/discord.py (100%) rename src/{modules => applications}/games_list/games_list.py (100%) rename src/{modules => applications}/scheduler_sync/__init__.py (100%) rename src/{modules => applications}/scheduler_sync/comparators.py (100%) rename src/{modules => applications}/scheduler_sync/discord_events.py (100%) rename src/{modules => applications}/scheduler_sync/synchronizer.py (100%) rename src/{modules => applications}/scheduler_sync/tasks.py (100%) rename src/{modules => applications}/scheduler_sync/twitch_events.py (100%) rename src/{modules => applications}/stream_notifications/__init__.py (100%) rename src/{modules => applications}/stream_notifications/messages_proc.py (100%) rename src/{modules => applications}/stream_notifications/notification.py (100%) rename src/{modules => applications}/stream_notifications/reward_redemption.py (100%) rename src/{modules => applications}/stream_notifications/sent_notifications.py (100%) rename src/{modules => applications}/stream_notifications/state.py (100%) rename src/{modules => applications}/stream_notifications/tasks.py (100%) rename src/{modules => applications}/stream_notifications/twitch/authorize.py (100%) rename src/{modules => applications}/stream_notifications/twitch/token_storage.py (100%) rename src/{modules => applications}/stream_notifications/twitch/webhook.py (100%) rename src/{modules => applications}/stream_notifications/watcher.py (100%) rename src/{modules => applications}/web_app/__init__.py (100%) rename src/{modules => applications}/web_app/app.py (100%) rename src/{modules => applications}/web_app/auth/authx.py (100%) rename src/{modules => applications}/web_app/frontend/index.css (100%) rename src/{modules => applications}/web_app/frontend/index.html (100%) rename src/{modules => applications}/web_app/frontend/index.js (100%) rename src/{modules => applications}/web_app/serializers/auth.py (100%) rename src/{modules => applications}/web_app/serializers/streamer.py (100%) rename src/{modules => applications}/web_app/services/oauth/authorization_url_getter.py (100%) rename src/{modules => applications}/web_app/services/oauth/process_callback.py (100%) rename src/{modules => applications}/web_app/services/oauth/providers/__init__.py (100%) rename src/{modules => applications}/web_app/services/oauth/providers/getter.py (100%) rename src/{modules => applications}/web_app/services/oauth/providers/twitch.py (100%) rename src/{modules => applications}/web_app/utils/static.py (100%) rename src/{modules => applications}/web_app/views/__init__.py (100%) rename src/{modules => applications}/web_app/views/auth.py (100%) rename src/{modules => applications}/web_app/views/streamer.py (100%) delete mode 100644 src/main.py delete mode 100644 src/modules/tasks.py diff --git a/src/domain/auth.py b/src/applications/common/domain/auth.py similarity index 100% rename from src/domain/auth.py rename to src/applications/common/domain/auth.py diff --git a/src/domain/streamers.py b/src/applications/common/domain/streamers.py similarity index 99% rename from src/domain/streamers.py rename to src/applications/common/domain/streamers.py index 990a826..c093dca 100644 --- a/src/domain/streamers.py +++ b/src/applications/common/domain/streamers.py @@ -1,31 +1,38 @@ from pydantic import BaseModel + class TwitchConfig(BaseModel): id: int name: str + class NotificationsConfig(BaseModel): start_stream: str change_category: str | None = None redemption_reward: str | None = None + class GamesListConfig(BaseModel): channel_id: int message_id: int + class DiscordConfig(BaseModel): guild_id: int notifications_channel_id: int games_list: GamesListConfig | None = None roles: dict[str, int] | None = None + class TelegramConfig(BaseModel): notifications_channel_id: int + class IntegrationsConfig(BaseModel): discord: DiscordConfig | None = None telegram: TelegramConfig | None = None + class StreamerConfig(BaseModel): twitch: TwitchConfig notifications: NotificationsConfig diff --git a/src/domain/users.py b/src/applications/common/domain/users.py similarity index 100% rename from src/domain/users.py rename to src/applications/common/domain/users.py diff --git a/src/repositories/base.py b/src/applications/common/repositories/base.py similarity index 100% rename from src/repositories/base.py rename to src/applications/common/repositories/base.py diff --git a/src/repositories/streamers.py b/src/applications/common/repositories/streamers.py similarity index 100% rename from src/repositories/streamers.py rename to src/applications/common/repositories/streamers.py diff --git a/src/repositories/users.py b/src/applications/common/repositories/users.py similarity index 85% rename from src/repositories/users.py rename to src/applications/common/repositories/users.py index 0eb0eb9..4b83d9d 100644 --- a/src/repositories/users.py +++ b/src/applications/common/repositories/users.py @@ -18,10 +18,10 @@ class UserRepository(BaseRepository): ) @classmethod - async def get_or_create_user(cls, newUser: CreateUser) -> User: + async def get_or_create_user(cls, new_user: CreateUser) -> User: filter_data = {} - for provider, data in newUser.oauths.items(): + for provider, data in new_user.oauths.items(): filter_data[f"oauths.{provider}.id"] = data.id async with cls.connect() as collection: @@ -29,7 +29,7 @@ class UserRepository(BaseRepository): filter_data, { "$setOnInsert": { - **newUser.model_dump(), + **new_user.model_dump(), } }, upsert=True, diff --git a/src/modules/games_list/__init__.py b/src/applications/games_list/__init__.py similarity index 100% rename from src/modules/games_list/__init__.py rename to src/applications/games_list/__init__.py diff --git a/src/modules/games_list/discord.py b/src/applications/games_list/discord.py similarity index 100% rename from src/modules/games_list/discord.py rename to src/applications/games_list/discord.py diff --git a/src/modules/games_list/games_list.py b/src/applications/games_list/games_list.py similarity index 100% rename from src/modules/games_list/games_list.py rename to src/applications/games_list/games_list.py diff --git a/src/modules/scheduler_sync/__init__.py b/src/applications/scheduler_sync/__init__.py similarity index 100% rename from src/modules/scheduler_sync/__init__.py rename to src/applications/scheduler_sync/__init__.py diff --git a/src/modules/scheduler_sync/comparators.py b/src/applications/scheduler_sync/comparators.py similarity index 100% rename from src/modules/scheduler_sync/comparators.py rename to src/applications/scheduler_sync/comparators.py diff --git a/src/modules/scheduler_sync/discord_events.py b/src/applications/scheduler_sync/discord_events.py similarity index 100% rename from src/modules/scheduler_sync/discord_events.py rename to src/applications/scheduler_sync/discord_events.py diff --git a/src/modules/scheduler_sync/synchronizer.py b/src/applications/scheduler_sync/synchronizer.py similarity index 100% rename from src/modules/scheduler_sync/synchronizer.py rename to src/applications/scheduler_sync/synchronizer.py diff --git a/src/modules/scheduler_sync/tasks.py b/src/applications/scheduler_sync/tasks.py similarity index 100% rename from src/modules/scheduler_sync/tasks.py rename to src/applications/scheduler_sync/tasks.py diff --git a/src/modules/scheduler_sync/twitch_events.py b/src/applications/scheduler_sync/twitch_events.py similarity index 100% rename from src/modules/scheduler_sync/twitch_events.py rename to src/applications/scheduler_sync/twitch_events.py diff --git a/src/modules/stream_notifications/__init__.py b/src/applications/stream_notifications/__init__.py similarity index 100% rename from src/modules/stream_notifications/__init__.py rename to src/applications/stream_notifications/__init__.py diff --git a/src/modules/stream_notifications/messages_proc.py b/src/applications/stream_notifications/messages_proc.py similarity index 100% rename from src/modules/stream_notifications/messages_proc.py rename to src/applications/stream_notifications/messages_proc.py diff --git a/src/modules/stream_notifications/notification.py b/src/applications/stream_notifications/notification.py similarity index 100% rename from src/modules/stream_notifications/notification.py rename to src/applications/stream_notifications/notification.py diff --git a/src/modules/stream_notifications/reward_redemption.py b/src/applications/stream_notifications/reward_redemption.py similarity index 100% rename from src/modules/stream_notifications/reward_redemption.py rename to src/applications/stream_notifications/reward_redemption.py diff --git a/src/modules/stream_notifications/sent_notifications.py b/src/applications/stream_notifications/sent_notifications.py similarity index 100% rename from src/modules/stream_notifications/sent_notifications.py rename to src/applications/stream_notifications/sent_notifications.py diff --git a/src/modules/stream_notifications/state.py b/src/applications/stream_notifications/state.py similarity index 100% rename from src/modules/stream_notifications/state.py rename to src/applications/stream_notifications/state.py diff --git a/src/modules/stream_notifications/tasks.py b/src/applications/stream_notifications/tasks.py similarity index 100% rename from src/modules/stream_notifications/tasks.py rename to src/applications/stream_notifications/tasks.py diff --git a/src/modules/stream_notifications/twitch/authorize.py b/src/applications/stream_notifications/twitch/authorize.py similarity index 100% rename from src/modules/stream_notifications/twitch/authorize.py rename to src/applications/stream_notifications/twitch/authorize.py diff --git a/src/modules/stream_notifications/twitch/token_storage.py b/src/applications/stream_notifications/twitch/token_storage.py similarity index 100% rename from src/modules/stream_notifications/twitch/token_storage.py rename to src/applications/stream_notifications/twitch/token_storage.py diff --git a/src/modules/stream_notifications/twitch/webhook.py b/src/applications/stream_notifications/twitch/webhook.py similarity index 100% rename from src/modules/stream_notifications/twitch/webhook.py rename to src/applications/stream_notifications/twitch/webhook.py diff --git a/src/modules/stream_notifications/watcher.py b/src/applications/stream_notifications/watcher.py similarity index 100% rename from src/modules/stream_notifications/watcher.py rename to src/applications/stream_notifications/watcher.py diff --git a/src/modules/web_app/__init__.py b/src/applications/web_app/__init__.py similarity index 100% rename from src/modules/web_app/__init__.py rename to src/applications/web_app/__init__.py diff --git a/src/modules/web_app/app.py b/src/applications/web_app/app.py similarity index 100% rename from src/modules/web_app/app.py rename to src/applications/web_app/app.py diff --git a/src/modules/web_app/auth/authx.py b/src/applications/web_app/auth/authx.py similarity index 100% rename from src/modules/web_app/auth/authx.py rename to src/applications/web_app/auth/authx.py diff --git a/src/modules/web_app/frontend/index.css b/src/applications/web_app/frontend/index.css similarity index 100% rename from src/modules/web_app/frontend/index.css rename to src/applications/web_app/frontend/index.css diff --git a/src/modules/web_app/frontend/index.html b/src/applications/web_app/frontend/index.html similarity index 100% rename from src/modules/web_app/frontend/index.html rename to src/applications/web_app/frontend/index.html diff --git a/src/modules/web_app/frontend/index.js b/src/applications/web_app/frontend/index.js similarity index 100% rename from src/modules/web_app/frontend/index.js rename to src/applications/web_app/frontend/index.js diff --git a/src/modules/web_app/serializers/auth.py b/src/applications/web_app/serializers/auth.py similarity index 100% rename from src/modules/web_app/serializers/auth.py rename to src/applications/web_app/serializers/auth.py diff --git a/src/modules/web_app/serializers/streamer.py b/src/applications/web_app/serializers/streamer.py similarity index 100% rename from src/modules/web_app/serializers/streamer.py rename to src/applications/web_app/serializers/streamer.py diff --git a/src/modules/web_app/services/oauth/authorization_url_getter.py b/src/applications/web_app/services/oauth/authorization_url_getter.py similarity index 100% rename from src/modules/web_app/services/oauth/authorization_url_getter.py rename to src/applications/web_app/services/oauth/authorization_url_getter.py diff --git a/src/modules/web_app/services/oauth/process_callback.py b/src/applications/web_app/services/oauth/process_callback.py similarity index 100% rename from src/modules/web_app/services/oauth/process_callback.py rename to src/applications/web_app/services/oauth/process_callback.py diff --git a/src/modules/web_app/services/oauth/providers/__init__.py b/src/applications/web_app/services/oauth/providers/__init__.py similarity index 100% rename from src/modules/web_app/services/oauth/providers/__init__.py rename to src/applications/web_app/services/oauth/providers/__init__.py diff --git a/src/modules/web_app/services/oauth/providers/getter.py b/src/applications/web_app/services/oauth/providers/getter.py similarity index 100% rename from src/modules/web_app/services/oauth/providers/getter.py rename to src/applications/web_app/services/oauth/providers/getter.py diff --git a/src/modules/web_app/services/oauth/providers/twitch.py b/src/applications/web_app/services/oauth/providers/twitch.py similarity index 100% rename from src/modules/web_app/services/oauth/providers/twitch.py rename to src/applications/web_app/services/oauth/providers/twitch.py diff --git a/src/modules/web_app/utils/static.py b/src/applications/web_app/utils/static.py similarity index 100% rename from src/modules/web_app/utils/static.py rename to src/applications/web_app/utils/static.py diff --git a/src/modules/web_app/views/__init__.py b/src/applications/web_app/views/__init__.py similarity index 100% rename from src/modules/web_app/views/__init__.py rename to src/applications/web_app/views/__init__.py diff --git a/src/modules/web_app/views/auth.py b/src/applications/web_app/views/auth.py similarity index 100% rename from src/modules/web_app/views/auth.py rename to src/applications/web_app/views/auth.py diff --git a/src/modules/web_app/views/streamer.py b/src/applications/web_app/views/streamer.py similarity index 100% rename from src/modules/web_app/views/streamer.py rename to src/applications/web_app/views/streamer.py diff --git a/src/main.py b/src/main.py deleted file mode 100644 index 61b9988..0000000 --- a/src/main.py +++ /dev/null @@ -1,45 +0,0 @@ -import logging -import sys - -from modules.games_list import start as start_games_list_module -from modules.stream_notifications import start as start_stream_notifications_module - -from core.mongo import mongo_manager -from core.redis import redis_manager -from core.broker import broker - - -logging.basicConfig(level=logging.INFO) - -logger = logging.getLogger(__name__) -logger.setLevel(logging.INFO) - - -async def main(): - logger.info("Starting services...") - - if len(sys.argv) != 2: - raise RuntimeError("Usage: python main.py ") - - module = sys.argv[1] - - await mongo_manager.init() - await redis_manager.init() - - if not broker.is_worker_process: - await broker.startup() - - if module == "games_list": - await start_games_list_module() - elif module == "stream_notifications": - await start_stream_notifications_module() - else: - raise RuntimeError(f"Unknown module: {module}") - - exit(0) - - -if __name__ == "__main__": - from asyncio import run - - run(main()) diff --git a/src/modules/tasks.py b/src/modules/tasks.py deleted file mode 100644 index 1765381..0000000 --- a/src/modules/tasks.py +++ /dev/null @@ -1,2 +0,0 @@ -from modules.scheduler_sync.tasks import * # noqa: F403 -from modules.stream_notifications.tasks import * # noqa: F403