-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
39 lines (33 loc) · 1.23 KB
/
run.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
import logging
import sys
from argparse import ArgumentParser, Namespace
import bot
from config import TOKENS
LOGGING_LEVELS = {
'TEST': logging.DEBUG,
'PROD': logging.INFO
}
def parse_argv() -> Namespace:
parser = ArgumentParser(description="Starts telegram bot for lessons "
"schedule in HSE")
parser.add_argument('action', type=str,
help="run|update_schedules|init_db")
parser.add_argument('--token', '-t', type=str, default="TEST",
help="api token name (from config) for access to bot")
parser.add_argument('--workers', '-w', type=int, default=10,
help="number of workers for running bot")
return parser.parse_args()
if __name__ == '__main__':
args = parse_argv()
if args.action == "update_schedules":
bot.update_schedules.main()
elif args.action == "init_db":
bot.init_db()
elif args.action == "run":
bot.run(
token=TOKENS.get(args.token.upper(), TOKENS["TEST"]),
logger_level=LOGGING_LEVELS.get(args.token.upper(), logging.DEBUG),
workers=args.workers
)
else:
print(f"Wrong command: {args.action}", file=sys.stderr)