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 (