small bugfixes

master
b3yond 2018-03-28 20:24:21 +02:00
parent e38a32d888
commit 21f1e9ddb3
6 changed files with 114 additions and 18 deletions

View File

@ -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")

View File

@ -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()

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 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"))

View File

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

View File

@ -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=?;",