ticketfrei/ticketfrei.py

44 lines
1.3 KiB
Python
Raw Normal View History

2017-12-30 00:15:22 +00:00
#!/usr/bin/env python3
2017-07-20 20:30:43 +00:00
import logging
2017-06-17 16:15:13 +00:00
import pytoml as toml
import time
import sendmail
2017-06-17 16:15:13 +00:00
2017-06-17 18:49:30 +00:00
from retootbot import RetootBot
from retweetbot import RetweetBot
2017-06-17 20:11:44 +00:00
from trigger import Trigger
2017-06-17 18:27:53 +00:00
2017-06-17 17:37:33 +00:00
if __name__ == '__main__':
# read config in TOML format (https://github.com/toml-lang/toml#toml)
2017-12-30 09:32:20 +00:00
with open('config.toml') as configfile:
2017-06-17 18:49:30 +00:00
config = toml.load(configfile)
logger = logging.getLogger()
fh = logging.FileHandler(config['logging']['logpath'])
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
2017-07-20 20:30:43 +00:00
trigger = Trigger(config)
mbot = RetootBot(config)
tbot = RetweetBot(config)
2017-06-17 18:49:30 +00:00
try:
statuses = []
while True:
statuses = mbot.flow(trigger, statuses)
statuses = tbot.flow(trigger, to_tweet=statuses)
time.sleep(60)
except KeyboardInterrupt:
2017-12-30 00:15:22 +00:00
print("Good bye. Remember to restart the bot!")
2017-07-11 20:05:46 +00:00
except:
logger.error('Shutdown', exc_info=True)
tbot.save_last_mention()
try:
mailer = sendmail.Mailer(config)
mailer.send('', config['mail']['contact'],
'Ticketfrei Crash Report',
attachment=config['logging']['logpath'])
except:
logger.error('Mail sending failed', exc_info=True)