diff --git a/.gitignore b/.gitignore index 898786b..47b5316 100644 --- a/.gitignore +++ b/.gitignore @@ -39,5 +39,5 @@ coverage.xml *.pot # Sphinx documentation docs/_build/ -config.json +src/config.json .idea/ \ No newline at end of file diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..b2b1fc1 --- /dev/null +++ b/src/config.py @@ -0,0 +1,35 @@ +# Project: Telegram-IP-CALC +# Filename: config.py +# Create Date: 12.09.2022, 14:05 +# SantaSpeen Copyright (c) 2022 +import logging +import json +import os + +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)-29s - %(levelname)-5s - %(message)s") + + +class Config: + + # noinspection PyTypeChecker + def __init__(self, config_file="config.json"): + self.log = logging.getLogger(__name__) + self.debug = self.log.debug + + self.config_file = config_file + self.raw_config: dict = None + + self.token: str = None + + self._read_config() + + def _read_config(self): + self.debug("_read_config(self)") + if os.path.isfile(self.config_file): + self.log.info(f"Config file: %s - found" % self.config_file) + with open(self.config_file, 'r', encoding='utf-8') as f: + self.raw_config = json.load(f) + else: + raise FileNotFoundError("Cannot found config file at %s." % self.config_file) + + self.token = self.raw_config.get("token") diff --git a/main.py b/src/main.py similarity index 86% rename from main.py rename to src/main.py index 0b97ed3..f6d0cf3 100644 --- a/main.py +++ b/src/main.py @@ -1,4 +1,19 @@ +# Project: Telegram-IP-CALC +# Filename: main.py +# Create Date: +# Marsh232 Copyright (c) 2022 +# SantaSpeen Copyright (c) 2022 + import ipaddress +import logging +from aiogram import Bot + +from src.config import Config + +config = Config("config.json") +log = logging.getLogger("Bot") + +bot = Bot(token=config.token) def main(ip):