From d8338b035147b49716094bded293c0090806b712 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Tue, 11 Nov 2025 15:26:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B4=D0=BB=D1=8F=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D1=83=D1=81=D0=BA=D0=B0=20=D0=B2=20=D0=B2=D0=B8=D0=B4?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++-- config.py | 17 ----------------- database.py | 4 ++-- tg/__init__.py | 0 tg/{tg_bot.py => __main__.py} | 16 ++++++++++------ tg/tg_database.py | 2 +- vk/__init__.py | 0 vk/__main__.py | 17 +++++++++++++++++ vk/vk_bot.py | 11 ----------- vk/vk_database.py | 2 +- 10 files changed, 33 insertions(+), 40 deletions(-) delete mode 100644 config.py create mode 100644 tg/__init__.py rename tg/{tg_bot.py => __main__.py} (50%) create mode 100644 vk/__init__.py create mode 100644 vk/__main__.py delete mode 100644 vk/vk_bot.py diff --git a/.gitignore b/.gitignore index 0e45f09..48e74b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .idea .venv __pycache__ -bot.db -config.json +*.db +*.json diff --git a/config.py b/config.py deleted file mode 100644 index 123fa48..0000000 --- a/config.py +++ /dev/null @@ -1,17 +0,0 @@ -import json - - -# Config = { -# api_token: "xxxxxxxx" -# } -Config = {} - - -def config_load(): - global Config - with open('config.json', 'r') as file: - Config = json.load(file) - - -config_load() -print('Конфигурация загружена.') diff --git a/database.py b/database.py index 36a767c..ccac189 100644 --- a/database.py +++ b/database.py @@ -3,8 +3,8 @@ from typing import List class BasicDatabase: - def __init__(self): - self.conn = sqlite3.connect('bot.db') + def __init__(self, filename: str): + self.conn = sqlite3.connect(filename) self.conn.row_factory = sqlite3.Row self.cursor = self.conn.cursor() diff --git a/tg/__init__.py b/tg/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tg/tg_bot.py b/tg/__main__.py similarity index 50% rename from tg/tg_bot.py rename to tg/__main__.py index bef74cc..c767562 100644 --- a/tg/tg_bot.py +++ b/tg/__main__.py @@ -1,14 +1,18 @@ import asyncio +import json from aiogram import Bot, Dispatcher -import config -import handlers -import tasks +from . import handlers +from . import tasks async def main() -> None: - bot = Bot(token=config.Config['api_token']) + with open('tg.json', 'r') as file: + config = json.load(file) + print('Конфигурация загружена.') + + bot = Bot(token=config['api_token']) dp = Dispatcher() dp.include_router(handlers.router) @@ -16,5 +20,5 @@ async def main() -> None: asyncio.create_task(tasks.daily_maintenance_task(bot)) await dp.start_polling(bot) - -asyncio.run(main()) +if __name__ == '__main__': + asyncio.run(main()) diff --git a/tg/tg_database.py b/tg/tg_database.py index 02cb972..2635f20 100644 --- a/tg/tg_database.py +++ b/tg/tg_database.py @@ -3,7 +3,7 @@ import database class TgDatabase(database.BasicDatabase): def __init__(self): - super().__init__() + super().__init__('tg.db') self.cursor.execute(""" CREATE TABLE IF NOT EXISTS chats ( diff --git a/vk/__init__.py b/vk/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vk/__main__.py b/vk/__main__.py new file mode 100644 index 0000000..efae4a9 --- /dev/null +++ b/vk/__main__.py @@ -0,0 +1,17 @@ +import json + +from . import handlers +from . import tasks + +from vkbottle.bot import Bot as VkBot + + +if __name__ == '__main__': + with open('vk.json', 'r') as file: + config = json.load(file) + print('Конфигурация загружена.') + + bot = VkBot(config['api_token'], labeler=handlers.labeler) + bot.loop_wrapper.on_startup.append(tasks.startup_task(bot.api)) + bot.loop_wrapper.add_task(tasks.daily_maintenance_task(bot.api)) + bot.run_forever() diff --git a/vk/vk_bot.py b/vk/vk_bot.py deleted file mode 100644 index ff8f9e5..0000000 --- a/vk/vk_bot.py +++ /dev/null @@ -1,11 +0,0 @@ -import config -import handlers -import tasks - -from vkbottle.bot import Bot as VkBot - - -bot = VkBot(config.Config['api_token'], labeler=handlers.labeler) -bot.loop_wrapper.on_startup.append(tasks.startup_task(bot.api)) -bot.loop_wrapper.add_task(tasks.daily_maintenance_task(bot.api)) -bot.run_forever() diff --git a/vk/vk_database.py b/vk/vk_database.py index 7c3f383..437c4c0 100644 --- a/vk/vk_database.py +++ b/vk/vk_database.py @@ -3,7 +3,7 @@ import database class VkDatabase(database.BasicDatabase): def __init__(self): - super().__init__() + super().__init__('vk.db') self.cursor.execute(""" CREATE TABLE IF NOT EXISTS chats (