-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (32 loc) · 1.16 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
#!/usr/bin/python
import configparser
import logging
import os
from pr0gramm.bot import Pr0grammBot
log = logging.getLogger('pr0Bot.main')
# set logging level for telegram bot explicit to WARN so we get only relevant messages
logging.getLogger('telegram.bot').setLevel(logging.WARN)
def main():
logging.basicConfig(level=logging.INFO)
log.info('Starting up pr0gramm bot...')
log.info('Reading config file...')
config = configparser.RawConfigParser(allow_no_value=True)
config_file_name = 'config.cfg'
read_files = config.read(config_file_name)
if not read_files:
log.critical('No config file found. Exit!')
exit(1)
if not os.path.exists(config.get('b0t', 'tmp_dir')):
try:
os.makedirs(config.get('b0t', 'tmp_dir'))
raise OSError
except OSError as e:
log.critical('Could not create tmp directory %s', e)
exit(1)
if not os.access(config.get('b0t', 'tmp_dir'), os.W_OK):
log.warn('Temporary directory (%s) is not writable', config.get('b0t', 'tmp_dir'))
bot = Pr0grammBot(config)
while True:
bot.run()
if __name__ == '__main__':
main()