from pathlib import Path from pprint import pprint from pysondb import db from rich import print from rich.logging import RichHandler from meta.logger import Logger, logging from meta.user import User, Task, TodaysTasks DictType = Dict[str, Union[str, int, Dict[str, Union[int, str]]]] DB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "db.json") # stop imported loggers logging.getLogger("pysondb").setLevel(logging.WARNING) logging.getLogger("filelock").setLevel(logging.WARNING) logging.getLogger("filelock").addHandler(RichHandler()) # db loggers db_log = logging.getLogger("database") db_logger = Logger(logger=db_log, base_level=logging.DEBUG, filename="") if not Path(DB_PATH).is_file(): with open(DB_PATH, "w") as f: f.write('{"data":[]}') class Database: def __init__(self) -> None: self._db = db.getDb(DB_PATH)
import time import uuid from collections import deque from typing import Deque, Dict, Union, List from meta.logger import Logger, logging from .user import NonUserInfo, Task, User, UserCmd, UserQueueData q_log = logging.getLogger("UserQueueHandler") q_logger = Logger(q_log, base_level=logging.DEBUG, filename="") ch_log = logging.getLogger("UserCommandHandler") ch_logger = Logger(ch_log, base_level=logging.DEBUG, filename="") th_log = logging.getLogger("UserTaskHandler") th_logger = Logger(th_log, base_level=logging.DEBUG, filename="") class UserQueueHandler: def __init__(self) -> None: self._q: Deque[Union[UserQueueData, NonUserInfo]] = deque() def add_user(self, user: UserQueueData) -> None: q_logger.log(logging.DEBUG, message=f"Got user {user}") self._q.append(user) def get_user(self) -> UserQueueData: if self._q: user = self._q.popleft() q_logger.log(logging.DEBUG, message=f"Popped user {user}")
from meta.logger import Logger, logging from meta.user import UserQueueData, UserCommands from meta.handlers import UserCommandHandler, UserQueueHandler, UserTaskHandler from database.message_id import MessageID from .bot_func import parse_text, send_cmd_time_out, todays_tasks_func, his_delete from .keyboards import main_keyboard pretty.install() ENV_FILE = os.path.join(Path(__file__).parent.parent, ".env") load_dotenv(dotenv_path=ENV_FILE) # stop other loggers from imported modules logging.getLogger("urllib3").setLevel(logging.WARNING) logging.getLogger("schedule").setLevel(logging.WARNING) # loggers b_l = logging.getLogger("bot") bot_logger = Logger(b_l, base_level=logging.INFO, filename="bot.log") t_log = logging.getLogger("bot_text") t_logger = Logger(t_log, base_level=logging.DEBUG, filename="") # handlers user_q_handler = UserQueueHandler() user_cmd_handler = UserCommandHandler() user_task_handler = UserTaskHandler() messsage_id = MessageID()
from datetime import datetime from typing import List from time import sleep from telebot import TeleBot import telebot from meta.logger import Logger, logging from meta.user import TodaysTasks, UserQueueData, UserCommands, UserCmd, User from meta.handlers import UserCommandHandler, UserTaskHandler from database.database import Database from database.message_id import MessageID bf_log = logging.getLogger("bot_func") bf_logger = Logger(bf_log, base_level=logging.DEBUG, filename="") db = Database() msg_id_db = MessageID() def set_cmd_handler(_id, cmd_handler: UserCommandHandler, cmd: UserCommands): cmd_handler.set_user_command( user_id=_id, cmd=UserCmd( time_inserted=int(time.time()), cmd=cmd, ), )
import os from typing import List from pathlib import Path from meta.logger import Logger, logging from pysondb import db from rich.logging import RichHandler # stop imported loggers logging.getLogger("pysondb").setLevel(logging.WARNING) logging.getLogger("filelock").setLevel(logging.WARNING) logging.getLogger("filelock").addHandler(RichHandler()) # db loggers ms_log = logging.getLogger("msg_id") ms_logger = Logger(logger=ms_log, base_level=logging.DEBUG, filename="message_id.log") DB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "msg_id.json") if not Path(DB_PATH).is_file(): with open(DB_PATH, "w") as f: f.write('{"data":[]}') class MessageID: def __init__(self) -> None: self._db = db.getDb(filename=DB_PATH)