ticketfrei can be imported now, takes care of loading config & logging

This commit is contained in:
b3yond 2018-03-23 11:05:24 +01:00
parent b9613a60de
commit 32e86a3c0e
8 changed files with 35 additions and 32 deletions

5
db.py
View file

@ -5,7 +5,7 @@ import jwt
from os import path, urandom
from pylibscrypt import scrypt_mcf, scrypt_mcf_check
import sqlite3
import pytoml as toml
import ticketfrei
from mastodon import Mastodon
@ -20,8 +20,7 @@ class DB(object):
self.create()
print("Initialized new sqlite database.")
self.secret = urandom(32)
with open('config.toml') as configfile:
self.config = toml.load(configfile)
self.config = ticketfrei.get_config()
def create(self):
# init db

View file

@ -5,7 +5,7 @@ import base64
import bottle
import sqlite3
import sendmail
import pytoml as toml
import ticketfrei
import jwt
import pylibscrypt
import smtplib
@ -345,8 +345,7 @@ class StripPathMiddleware(object):
if __name__ == "__main__":
global config
with open('../config.toml') as configfile:
config = toml.load(configfile)
config = ticketfrei.get_config()
global db
global secret

View file

@ -7,7 +7,6 @@ import trigger
import datetime
import email
import logging
import pytoml as toml
import imaplib
import report
@ -173,9 +172,8 @@ class Mailbot(object):
if __name__ == "__main__":
# read config in TOML format (https://github.com/toml-lang/toml#toml)
with open('config.toml') as configfile:
config = toml.load(configfile)
import ticketfrei
config = ticketfrei.get_config()
# set log file
logger = logging.getLogger()

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python3
import pytoml as toml
import mastodon
import os
import pickle
@ -129,9 +128,8 @@ class RetootBot(object):
if __name__ == '__main__':
# read config in TOML format (https://github.com/toml-lang/toml#toml)
with open('config.toml') as configfile:
config = toml.load(configfile)
import ticketfrei
config = ticketfrei.get_config()
fh = logging.FileHandler(config['logging']['logpath'])
fh.setLevel(logging.DEBUG)

View file

@ -3,7 +3,6 @@
import tweepy
import re
import requests
import pytoml as toml
import trigger
from time import sleep
import report
@ -203,9 +202,8 @@ class RetweetBot(object):
if __name__ == "__main__":
# get the config dict of dicts
with open('config.toml') as configfile:
config = toml.load(configfile)
import ticketfrei
config = ticketfrei.get_config()
# set log file
fh = logging.FileHandler(config['logging']['logpath'])

View file

@ -2,7 +2,6 @@
import smtplib
import ssl
import pytoml as toml
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
@ -67,9 +66,8 @@ class Mailer(object):
# For testing:
if __name__ == '__main__':
# read config in TOML format (https://github.com/toml-lang/toml#toml)
with open('config.toml') as configfile:
config = toml.load(configfile)
import ticketfrei
config = ticketfrei.get_config()
m = Mailer(config)
print(m.send("This is a test mail.", m.fromaddr, "Test"))

View file

@ -10,21 +10,32 @@ from retweetbot import RetweetBot
from mailbot import Mailbot
from trigger import Trigger
if __name__ == '__main__':
def set_logfile(config):
logfile = config['logging']['logpath']
logger = logging.getLogger()
fh = logging.FileHandler(logfile)
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
return logger
def get_config():
# read config in TOML format (https://github.com/toml-lang/toml#toml)
with open('config.toml') as configfile:
config = toml.load(configfile)
return config
def run():
# get config
config = get_config()
# set log file
logger = logging.getLogger()
fh = logging.FileHandler(config['logging']['logpath'])
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
logger = set_logfile(config)
# set trigger
trigger = Trigger(config)
# initialize bots
bots = []
if config["muser"]["enabled"] != "false":
bots.append(RetootBot(config))
if config["tuser"]["enabled"] != "false":
@ -59,3 +70,7 @@ if __name__ == '__main__':
attachment=config['logging']['logpath'])
except:
logger.error('Mail sending failed', exc_info=True)
if __name__ == '__main__':
run()

View file

@ -1,9 +1,7 @@
#!/usr/bin/env python
import pytoml as toml
import os
import re
class Trigger(object):
"""
This class provides a filter to test a string against.
@ -59,8 +57,8 @@ class Trigger(object):
if __name__ == "__main__":
with open("config.toml", "r") as configfile:
config = toml.load(configfile)
import ticketfrei
config = ticketfrei.get_config()
print("testing the trigger")
trigger = Trigger(config)