-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
executable file
·88 lines (65 loc) · 1.99 KB
/
bot.py
File metadata and controls
executable file
·88 lines (65 loc) · 1.99 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
import os
from functools import wraps
import argparse
import logging
from app.logger import get_logger
log = get_logger(__name__)
try:
import aiohttp_autoreload
auto_reload_available = True
except ImportError:
auto_reload_available = None
parser = argparse.ArgumentParser(description="Aiogram executor")
parser.add_argument(
"--reload",
"-r",
required=False,
action="store_true",
help="run the Application in auto-reload mode"
"(aiohttp_autoreload need to be installed)",
)
parser.add_argument(
"--debug",
"-d",
required=False,
action="store_true",
help="run application in debug mode",
)
args = parser.parse_args()
def arg_parser_mixin(func):
auto_reload = args.reload
debug = args.debug
@wraps(func)
def wrapper(*args, **kwargs):
if (log_level := os.getenv("LOG_LEVEL", None)) is not None:
log.info(f"Setting Log level to {log_level}")
logging.basicConfig(level=logging.getLevelName(log_level.upper()))
if debug:
logging.basicConfig(level=logging.DEBUG)
os.environ["LOG_LEVEL"] = "debug"
else:
logging.basicConfig(level=logging.INFO)
if auto_reload_available and auto_reload:
log.warning(
"Application started in auto-reload mode. "
"make sure to disable it in production server!"
)
aiohttp_autoreload.start()
elif auto_reload and not auto_reload_available:
log.error(
"auto-reload is enabled but 'aiohttp_autoreload' "
"is not installed! skipping..."
)
func(*args, **kwargs)
return wrapper
@arg_parser_mixin
def start_app():
"""start app and start aiohttp_autoreload for auto-reload
if aiohttp_autoreload installed and auto_reload enabled
"""
log.info("Starting application...")
from app.main import start
start()
if __name__ == "__main__":
start_app()