small bugfixes

This commit is contained in:
b3yond 2018-03-28 20:24:21 +02:00
parent 1dd75c10d5
commit ec3053a0ab
6 changed files with 114 additions and 18 deletions

View file

@ -20,14 +20,13 @@ class Mailbot(object):
other bots that it received mails. other bots that it received mails.
""" """
def __init__(self, uid, db): def __init__(self, uid):
""" """
Creates a Bot who listens to mails and forwards them to other Creates a Bot who listens to mails and forwards them to other
bots. bots.
:param config: (dictionary) config.toml as a dictionary of dictionaries
""" """
self.user = User(db, uid) self.user = User(uid)
try: try:
self.last_mail = self.user.get_seen_mail() self.last_mail = self.user.get_seen_mail()
@ -115,7 +114,7 @@ class Mailbot(object):
:param status: (report.Report object) :param status: (report.Report object)
""" """
mailer = sendmail.Mailer(config) mailer = sendmail.Mailer()
mailer.send(status.format(), self.mailinglist, mailer.send(status.format(), self.mailinglist,
"Warnung: Kontrolleure gesehen") "Warnung: Kontrolleure gesehen")

View file

@ -24,16 +24,13 @@ class TwitterBot(object):
last_mention: the ID of the last tweet which mentioned you last_mention: the ID of the last tweet which mentioned you
""" """
def __init__(self, uid, db): def __init__(self, uid):
""" """
Initializes the bot and loads all the necessary data. Initializes the bot and loads all the necessary data.
:param config: (dictionary) config.toml as a dictionary of dictionaries
:param history_path: Path to the file with ID of the last retweeted
Tweet Tweet
""" """
self.db = db self.user = User(uid)
self.user = User(db, uid)
# initialize API access # initialize API access
keys = self.get_api_keys() keys = self.get_api_keys()

104
mall bugfixes Normal file
View file

@ -0,0 +1,104 @@
diff --git a/active_bots/mailbot.py b/active_bots/mailbot.py
index a98872a..a11231f 100644
--- a/active_bots/mailbot.py
+++ b/active_bots/mailbot.py
@@ -20,14 +20,13 @@ class Mailbot(object):
other bots that it received mails.
"""

- def __init__(self, uid, db):
+ def __init__(self, uid):
"""
Creates a Bot who listens to mails and forwards them to other
bots.

- :param config: (dictionary) config.toml as a dictionary of dictionaries
"""
- self.user = User(db, uid)
+ self.user = User(uid)

try:
self.last_mail = self.user.get_seen_mail()
@@ -115,7 +114,7 @@ class Mailbot(object):

:param status: (report.Report object)
"""
- mailer = sendmail.Mailer(config)
+ mailer = sendmail.Mailer()
mailer.send(status.format(), self.mailinglist,
"Warnung: Kontrolleure gesehen")

diff --git a/active_bots/twitterbot.py b/active_bots/twitterbot.py
index 787cdfb..065da45 100755
--- a/active_bots/twitterbot.py
+++ b/active_bots/twitterbot.py
@@ -24,16 +24,13 @@ class TwitterBot(object):
last_mention: the ID of the last tweet which mentioned you
"""

- def __init__(self, uid, db):
+ def __init__(self, uid):
"""
Initializes the bot and loads all the necessary data.

- :param config: (dictionary) config.toml as a dictionary of dictionaries
- :param history_path: Path to the file with ID of the last retweeted
Tweet
"""
- self.db = db
- self.user = User(db, uid)
+ self.user = User(uid)

# initialize API access
keys = self.get_api_keys()
diff --git a/sendmail.py b/sendmail.py
index df91d1d..93028d9 100755
--- a/sendmail.py
+++ b/sendmail.py
@@ -2,6 +2,7 @@

import smtplib
import ssl
+from config import config
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
@@ -12,13 +13,12 @@ class Mailer(object):
Maintains the connection to the mailserver and sends text to users.
"""

- def __init__(self, config):
+ def __init__(self):
"""
Creates an SMTP client to send a mail. Is called only once
when you actually want to send a mail. After you sent the
mail, the SMTP client is shut down again.

- :param config: The config file generated from config.toml
"""
# This generates the From address by stripping the part until the first
# period from the mail server address and won't work always.
@@ -65,9 +65,5 @@ class Mailer(object):

# For testing:
if __name__ == '__main__':
- import prepare
-
- config = prepare.get_config()
-
- m = Mailer(config)
+ m = Mailer()
print(m.send("This is a test mail.", m.fromaddr, "Test"))
diff --git a/user.py b/user.py
index c4e99e4..ce95cd3 100644
--- a/user.py
+++ b/user.py
@@ -53,7 +53,7 @@ class User(object):
return jwt.encode({
'email': email,
'uid': self.uid
- }, self.secret).decode('ascii')
+ }, db.secret).decode('ascii')

def is_appropriate(self, report):
db.execute("SELECT pattern FROM triggerpatterns WHERE user_id=?;",

View file

@ -2,6 +2,7 @@
import smtplib import smtplib
import ssl import ssl
from config import config
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.mime.application import MIMEApplication from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
@ -12,13 +13,12 @@ class Mailer(object):
Maintains the connection to the mailserver and sends text to users. Maintains the connection to the mailserver and sends text to users.
""" """
def __init__(self, config): def __init__(self):
""" """
Creates an SMTP client to send a mail. Is called only once Creates an SMTP client to send a mail. Is called only once
when you actually want to send a mail. After you sent the when you actually want to send a mail. After you sent the
mail, the SMTP client is shut down again. mail, the SMTP client is shut down again.
:param config: The config file generated from config.toml
""" """
# This generates the From address by stripping the part until the first # This generates the From address by stripping the part until the first
# period from the mail server address and won't work always. # period from the mail server address and won't work always.
@ -65,9 +65,5 @@ class Mailer(object):
# For testing: # For testing:
if __name__ == '__main__': if __name__ == '__main__':
import prepare m = Mailer()
config = prepare.get_config()
m = Mailer(config)
print(m.send("This is a test mail.", m.fromaddr, "Test")) print(m.send("This is a test mail.", m.fromaddr, "Test"))

View file

@ -20,7 +20,7 @@ class SessionPlugin(object):
uid = request.get_cookie('uid', secret=db.secret) uid = request.get_cookie('uid', secret=db.secret)
if uid is None: if uid is None:
return redirect(self.loginpage) return redirect(self.loginpage)
kwargs[self.keyword] = User(db, uid) kwargs[self.keyword] = User(uid)
return callback(*args, **kwargs) return callback(*args, **kwargs)
return wrapper return wrapper

View file

@ -53,7 +53,7 @@ class User(object):
return jwt.encode({ return jwt.encode({
'email': email, 'email': email,
'uid': self.uid 'uid': self.uid
}, self.secret).decode('ascii') }, db.secret).decode('ascii')
def is_appropriate(self, report): def is_appropriate(self, report):
db.execute("SELECT pattern FROM triggerpatterns WHERE user_id=?;", db.execute("SELECT pattern FROM triggerpatterns WHERE user_id=?;",