-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (46 loc) · 1.4 KB
/
main.py
File metadata and controls
56 lines (46 loc) · 1.4 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
import logging
import os
import shelve
import yaml
from soroush_python_sdk import Client
import admin_commands
import config
import logging.config
from quran import start_bot
def setup_logging(default_path='logging.yaml', default_level=logging.INFO, env_key='LOG_CFG'):
"""Setup logging configuration
"""
path = os.path.join(os.path.dirname(__file__), default_path)
value = os.getenv(env_key, None)
if value:
path = value
if os.path.exists(path):
with open(path, 'rt') as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
else:
logging.basicConfig(level=default_level)
logging.warning("log config doesn't detected. using defaults")
logging.getLogger('urllib3').setLevel(logging.CRITICAL)
logging.getLogger('sseclient').setLevel(logging.INFO)
def main():
res = None
try:
res = shelve.open('medias.dbm')
bot = Client(config.bot_token)
logging.info('starting bot...')
admin_commands.bot_start_report(bot, res=res)
start_bot(bot, res)
except Exception as e:
logging.exception('Bad things happend!')
try:
for admin in config.bot_admins:
bot.send_text(admin, str(e))
except Exception:
pass
finally:
if res:
res.close()
if __name__ == '__main__':
setup_logging()
main()