Make code even more PEP8 compliant
It could be made even more compliant, but that would actually decrease readability imo.
This commit is contained in:
parent
72d6798022
commit
1703eb3802
|
|
@ -12,4 +12,3 @@ for loader, name, is_pkg in pkgutil.walk_packages(__path__):
|
||||||
|
|
||||||
globals()[name] = value
|
globals()[name] = value
|
||||||
__all__.append(name)
|
__all__.append(name)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ class Mailbot(Bot):
|
||||||
# returns a list of Report objects
|
# returns a list of Report objects
|
||||||
def crawl(self, user):
|
def crawl(self, user):
|
||||||
reports = []
|
reports = []
|
||||||
mails = mailbox.mbox('/var/mail/test') # todo: adjust to actual mailbox
|
# todo: adjust to actual mailbox
|
||||||
|
mails = mailbox.mbox('/var/mail/test')
|
||||||
for msg in mails:
|
for msg in mails:
|
||||||
if get_date_from_header(msg['Date']) > user.get_seen_mail():
|
if get_date_from_header(msg['Date']) > user.get_seen_mail():
|
||||||
reports.append(make_report(msg, user))
|
reports.append(make_report(msg, user))
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,20 @@ class TelegramBot(Bot):
|
||||||
user.save_seen_tg(update.update_id)
|
user.save_seen_tg(update.update_id)
|
||||||
if update.message.text.lower() == "/start":
|
if update.message.text.lower() == "/start":
|
||||||
user.add_telegram_subscribers(update.message.sender.id)
|
user.add_telegram_subscribers(update.message.sender.id)
|
||||||
tb.send_message(update.message.sender.id, "You are now subscribed to report notifications.")
|
tb.send_message(
|
||||||
|
update.message.sender.id,
|
||||||
|
"You are now subscribed to report notifications.")
|
||||||
# TODO: /start message should be set in frontend
|
# TODO: /start message should be set in frontend
|
||||||
elif update.message.text.lower() == "/stop":
|
elif update.message.text.lower() == "/stop":
|
||||||
user.remove_telegram_subscribers(update.message.sender.id)
|
user.remove_telegram_subscribers(update.message.sender.id)
|
||||||
tb.send_message(update.message.sender.id, "You are now unsubscribed from report notifications.")
|
tb.send_message(
|
||||||
|
update.message.sender.id,
|
||||||
|
"You are now unsubscribed from report notifications.")
|
||||||
# TODO: /stop message should be set in frontend
|
# TODO: /stop message should be set in frontend
|
||||||
elif update.message.text.lower() == "/help":
|
elif update.message.text.lower() == "/help":
|
||||||
tb.send_message(update.message.sender.id, "Send reports here to share them with other users. Use /start and /stop to get reports or not.")
|
tb.send_message(
|
||||||
|
update.message.sender.id,
|
||||||
|
"Send reports here to share them with other users. Use /start and /stop to get reports or not.")
|
||||||
# TODO: /help message should be set in frontend
|
# TODO: /help message should be set in frontend
|
||||||
else:
|
else:
|
||||||
reports.append(Report(update.message.sender.username, self,
|
reports.append(Report(update.message.sender.username, self,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class TwitterBot(Bot):
|
||||||
return reports # no twitter account for this user.
|
return reports # no twitter account for this user.
|
||||||
last_dm = user.get_seen_dm()
|
last_dm = user.get_seen_dm()
|
||||||
try:
|
try:
|
||||||
if last_dm == None:
|
if last_dm is None:
|
||||||
mentions = api.direct_messages()
|
mentions = api.direct_messages()
|
||||||
else:
|
else:
|
||||||
mentions = api.mentions_timeline(since_id=last_dm[0])
|
mentions = api.mentions_timeline(since_id=last_dm[0])
|
||||||
|
|
|
||||||
9
db.py
9
db.py
|
|
@ -223,7 +223,6 @@ class DB(object):
|
||||||
json = jwt.decode(token, self.secret)
|
json = jwt.decode(token, self.secret)
|
||||||
return json['email'], json['city']
|
return json['email'], json['city']
|
||||||
|
|
||||||
|
|
||||||
def confirm(self, token, city):
|
def confirm(self, token, city):
|
||||||
from user import User
|
from user import User
|
||||||
try:
|
try:
|
||||||
|
|
@ -262,10 +261,10 @@ u\d\d?"""
|
||||||
(uid, json['email']))
|
(uid, json['email']))
|
||||||
self.execute("""INSERT INTO telegram_accounts (user_id, apikey,
|
self.execute("""INSERT INTO telegram_accounts (user_id, apikey,
|
||||||
active) VALUES(?, ?, ?);""", (uid, "", 1))
|
active) VALUES(?, ?, ?);""", (uid, "", 1))
|
||||||
self.execute("INSERT INTO seen_telegrams (user_id, tg_id) VALUES (?,?);",
|
self.execute(
|
||||||
(uid, 0))
|
"INSERT INTO seen_telegrams (user_id, tg_id) VALUES (?,?);", (uid, 0))
|
||||||
self.execute("INSERT INTO seen_mail (user_id, mail_date) VALUES (?,?);",
|
self.execute(
|
||||||
(uid, 0))
|
"INSERT INTO seen_mail (user_id, mail_date) VALUES (?,?);", (uid, 0))
|
||||||
self.commit()
|
self.commit()
|
||||||
user = User(uid)
|
user = User(uid)
|
||||||
user.set_city(city)
|
user.set_city(city)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class Mailer(object):
|
||||||
try:
|
try:
|
||||||
context = ssl.create_default_context()
|
context = ssl.create_default_context()
|
||||||
self.s.starttls(context=context)
|
self.s.starttls(context=context)
|
||||||
except:
|
except BaseException: # TODO: Amend specific exception
|
||||||
logger.error('StartTLS failed.', exc_info=True)
|
logger.error('StartTLS failed.', exc_info=True)
|
||||||
self.s.login(config["mail"]["user"], config["mail"]["passphrase"])
|
self.s.login(config["mail"]["user"], config["mail"]["passphrase"])
|
||||||
|
|
||||||
|
|
|
||||||
1
user.py
1
user.py
|
|
@ -461,4 +461,3 @@ unsubscribe-link mitgeschickt.
|
||||||
masto_link, twit_link) VALUES(?,?,?,?,?,?)""",
|
masto_link, twit_link) VALUES(?,?,?,?,?,?)""",
|
||||||
(self.uid, city, markdown, mail_md, masto_link, twit_link))
|
(self.uid, city, markdown, mail_md, masto_link, twit_link))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue