forked from ticketfrei/ticketfrei
fixing #39 - saving last request in global var, not db.
This commit is contained in:
parent
9b3efd7bd2
commit
304d83ffad
|
@ -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-_]+)",
|
||||
|
|
|
@ -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):
|
||||
|
|
6
db.py
6
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,
|
||||
|
|
|
@ -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')
|
||||
|
|
10
user.py
10
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))
|
||||
|
|
Loading…
Reference in a new issue