diff --git a/main.py b/main.py index fd79822..7298251 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ import sys import colorama from aiogram import Bot, Dispatcher -from tgbot.data.config import BOT_TOKEN, scheduler, get_admins +from tgbot.data.config import BOT_TOKEN, BOT_SCHEDULER, get_admins from tgbot.database.db_helper import create_dbx from tgbot.middlewares import register_all_middlwares from tgbot.routers import register_all_routers @@ -20,13 +20,12 @@ colorama.init() # Запуск шедулеров async def scheduler_start(bot): - scheduler.add_job(autobackup_admin, "cron", hour=00, args=(bot,)) # Ежедневный Автобэкап в 00:00 - scheduler.add_job(autobackup_admin, "cron", hour=12, args=(bot,)) # Ежедневный Автобэкап в 12:00 + BOT_SCHEDULER.add_job(autobackup_admin, "cron", hour=00, args=(bot,)) # Ежедневный Автобэкап в 00:00 # Запуск бота и базовых функций async def main(): - scheduler.start() # Запуск Шедулера + BOT_SCHEDULER.start() # Запуск Шедулера dp = Dispatcher() # Образ Диспетчера arSession = AsyncRequestSession() # Пул асинхронной сессии запросов bot = Bot(token=BOT_TOKEN, parse_mode="HTML") # Образ Бота diff --git a/tgbot/data/config.py b/tgbot/data/config.py index 1a36fc9..55f6b2c 100644 --- a/tgbot/data/config.py +++ b/tgbot/data/config.py @@ -14,7 +14,7 @@ PATH_DATABASE = "tgbot/data/database.db" # Путь к БД PATH_LOGS = "tgbot/data/logs.log" # Путь к Логам # Образы и конфиги -scheduler = AsyncIOScheduler(timezone=BOT_TIMEZONE) # Образ шедулера +BOT_SCHEDULER = AsyncIOScheduler(timezone=BOT_TIMEZONE) # Образ шедулера start_status = True # Оповещение админам о запуске бота (True или False) diff --git a/tgbot/utils/const_functions.py b/tgbot/utils/const_functions.py index 102ec52..963eb5a 100644 --- a/tgbot/utils/const_functions.py +++ b/tgbot/utils/const_functions.py @@ -83,7 +83,7 @@ def ded(get_text: str) -> str: if get_text is not None: split_text = get_text.split("\n") if split_text[0] == "": split_text.pop(0) - if split_text[-1] == "": split_text.pop(-1) + if split_text[-1] == "": split_text.pop() save_text = [] for text in split_text: @@ -264,19 +264,23 @@ def is_bool(value: Union[bool, str, int]) -> bool: ######################################## ЧИСЛА ######################################## # Преобразование экспоненциальных чисел в читаемый вид (1e-06 -> 0.000001) -def snum(amount: Union[int, float]) -> str: - str_amount = str(amount) +def snum(amount: Union[int, float], remains: int = 2) -> str: + format_str = "{:." + str(remains) + "f}" + str_amount = format_str.format(float(amount)) - if "e" in str_amount: - decial = str_amount.split("e") - str_amount = format(((float(decial[0])) * (10 ** int(decial[1]))), ".8f") + if remains != 0: + if "." in str_amount: + remains_find = str_amount.find(".") + remains_save = remains_find + 8 - (8 - remains) + 1 + + str_amount = str_amount[:remains_save] if "." in str(str_amount): - while str(str_amount).endswith("0"): str_amount = str(str_amount)[:-1] + while str(str_amount).endswith('0'): str_amount = str(str_amount)[:-1] - if str(str_amount).endswith("."): str_amount = str(str_amount)[:-1] + if str(str_amount).endswith('.'): str_amount = str(str_amount)[:-1] - return str_amount + return str(str_amount) # Конвертация любого числа в вещественное, с удалением нулей в конце (remains - округление)