-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.py
45 lines (33 loc) · 1.11 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Main module"""
import logging
from telegram.ext import Updater
from module.data import config_map
from module.handlers import add_handlers, set_commands
from module.jobs import add_jobs
def setup_logging(logs_file: str) -> None:
"""Sets up the logging system.
Creates a file handler and a stream handler.
Args:
logs_file: path to the log file
"""
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger()
file_handler = logging.FileHandler(f"{logs_file}.log")
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
stdout_handler = logging.StreamHandler()
stdout_handler.setFormatter(formatter)
logger.addHandler(stdout_handler)
logger.setLevel(logging.INFO)
def main() -> None:
"""Main function"""
setup_logging("logfile")
logging.info("Initialization...")
updater = Updater(config_map["token"])
set_commands(updater)
add_handlers(updater.dispatcher)
add_jobs(updater.job_queue)
updater.start_polling()
updater.idle()
if __name__ == "__main__":
main()