diff --git a/active_bots/twitterbot.py b/active_bots/twitterbot.py index 081fc07..2bda8fb 100755 --- a/active_bots/twitterbot.py +++ b/active_bots/twitterbot.py @@ -7,6 +7,7 @@ import requests from time import time import report from bot import Bot +from backend import last_twitter_request logger = logging.getLogger(__name__) @@ -29,11 +30,9 @@ class TwitterBot(Bot): :return: reports: (list of report.Report objects) """ reports = [] - try: - if user.get_last_twitter_request() + 60 > time(): - return reports - except TypeError: - user.set_last_twitter_request(time()) + global last_twitter_request + if last_twitter_request + 60 > time(): + return reports try: api = self.get_api(user) except Exception: @@ -45,7 +44,7 @@ class TwitterBot(Bot): mentions = api.mentions_timeline() else: mentions = api.mentions_timeline(since_id=last_mention) - user.set_last_twitter_request(time()) + last_twitter_request = time() for status in mentions: text = re.sub( "(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)", diff --git a/backend.py b/backend.py index b9c60dc..13dcfe7 100755 --- a/backend.py +++ b/backend.py @@ -5,7 +5,7 @@ from config import config from db import db import logging from sendmail import sendmail -import time +from time import time def shutdown(): @@ -16,12 +16,15 @@ def shutdown(): exit(1) +last_twitter_request = time() + if __name__ == '__main__': logger = logging.getLogger() fh = logging.FileHandler('/var/log/ticketfrei/backend.log') fh.setLevel(logging.DEBUG) logger.addHandler(fh) + bots = [] for ActiveBot in active_bots.__dict__.values(): if isinstance(ActiveBot, type) and issubclass(ActiveBot, Bot): diff --git a/db.py b/db.py index 2e0306e..117cd8a 100644 --- a/db.py +++ b/db.py @@ -93,12 +93,6 @@ class DB(object): active INTEGER, FOREIGN KEY(user_id) REFERENCES user(id) ); - CREATE TABLE IF NOT EXISTS twitter_last_request ( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, - user_id INTEGER, - date INTEGER, - FOREIGN KEY(user_id) REFERENCES user(id) - ); CREATE TABLE IF NOT EXISTS telegram_accounts ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, user_id INTEGER, diff --git a/frontend.py b/frontend.py index 7a1df7a..8ae5273 100755 --- a/frontend.py +++ b/frontend.py @@ -231,8 +231,8 @@ def twitter_callback(user): @post('/login/mastodon') def login_mastodon(user): """ - Starts the mastodon OAuth authentication process. - :return: redirect to twitter. + Mastodon OAuth authentication process. + :return: redirect to city page. """ # get app tokens instance_url = request.forms.get('instance_url') diff --git a/user.py b/user.py index b2da2e6..a2e8821 100644 --- a/user.py +++ b/user.py @@ -144,16 +144,6 @@ schlitz keys.append(row[1]) return keys - def get_last_twitter_request(self): - db.execute("SELECT date FROM twitter_last_request WHERE user_id = ?;", - (self.uid,)) - return db.cur.fetchone()[0] - - def set_last_twitter_request(self, date): - db.execute("UPDATE twitter_last_request SET date = ? WHERE user_id = ?;", - (date, self.uid)) - db.commit() - def toot_is_seen(self, toot_uri): db.execute("SELECT COUNT(*) FROM seen_toots WHERE user_id = ? AND toot_uri = ?;", (self.uid, toot_uri))