-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·53 lines (43 loc) · 1.18 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
46
47
48
49
50
51
52
53
import argparse
import configparser
import json
import logging
import signal
import sys
from lib.bear import Bear
from lib.webServer import WebServer
parser = argparse.ArgumentParser()
parser.add_argument(
'-log',
'--loglevel',
default='info',
help='Provide logging level. Example --loglevel debug, default=warning'
)
args = parser.parse_args()
logging.basicConfig(level=args.loglevel.upper() )
logging.getLogger('asyncio').setLevel(logging.WARNING)
# read main config file
config = configparser.RawConfigParser()
config.read('config/main.cfg')
# read phrases config file
with open('config/phrases.json', 'r') as f:
phrases = json.load(f)
# sort phrases alphabetically by key
config.phrases = dict(sorted(phrases.items(), key = lambda kv:(kv[1], kv[0])))
# init bear
bear = Bear(config)
# init web framework
ws = WebServer(bear)
# properly handle SIGINT (ctrl-c)
def signal_handler(signal, frame):
raise KeyboardInterrupt
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
try:
bear.activate()
ws.start()
except KeyboardInterrupt:
pass
finally:
bear.deactivate()
sys.exit(0)