commit
9ca521493a
|
@ -5,7 +5,6 @@ import tweepy
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
import report
|
import report
|
||||||
import tfglobals
|
|
||||||
from time import time
|
from time import time
|
||||||
from bot import Bot
|
from bot import Bot
|
||||||
|
|
||||||
|
@ -29,8 +28,11 @@ class TwitterBot(Bot):
|
||||||
:return: reports: (list of report.Report objects)
|
:return: reports: (list of report.Report objects)
|
||||||
"""
|
"""
|
||||||
reports = []
|
reports = []
|
||||||
if tfglobals.last_twitter_request + 60 > time():
|
try:
|
||||||
return reports
|
if user.get_last_twitter_request() + 60 > time():
|
||||||
|
return reports
|
||||||
|
except TypeError:
|
||||||
|
user.set_last_twitter_request(time())
|
||||||
try:
|
try:
|
||||||
api = self.get_api(user)
|
api = self.get_api(user)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -41,7 +43,7 @@ class TwitterBot(Bot):
|
||||||
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])
|
||||||
tfglobals.last_twitter_request = time()
|
user.set_last_twitter_request(time())
|
||||||
for status in mentions:
|
for status in mentions:
|
||||||
text = re.sub(
|
text = re.sub(
|
||||||
"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
||||||
|
|
|
@ -7,7 +7,6 @@ import requests
|
||||||
from time import time
|
from time import time
|
||||||
import report
|
import report
|
||||||
from bot import Bot
|
from bot import Bot
|
||||||
import tfglobals
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -31,8 +30,11 @@ class TwitterBot(Bot):
|
||||||
"""
|
"""
|
||||||
reports = []
|
reports = []
|
||||||
#global last_twitter_request
|
#global last_twitter_request
|
||||||
if tfglobals.last_twitter_request + 60 > time():
|
try:
|
||||||
return reports
|
if user.get_last_twitter_request() + 60 > time():
|
||||||
|
return reports
|
||||||
|
except TypeError:
|
||||||
|
user.set_last_twitter_request(time())
|
||||||
try:
|
try:
|
||||||
api = self.get_api(user)
|
api = self.get_api(user)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
@ -46,7 +48,7 @@ class TwitterBot(Bot):
|
||||||
mentions = api.mentions_timeline()
|
mentions = api.mentions_timeline()
|
||||||
else:
|
else:
|
||||||
mentions = api.mentions_timeline(since_id=last_mention)
|
mentions = api.mentions_timeline(since_id=last_mention)
|
||||||
tfglobals.last_twitter_request = time()
|
user.set_last_twitter_request(time())
|
||||||
for status in mentions:
|
for status in mentions:
|
||||||
text = re.sub(
|
text = re.sub(
|
||||||
"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
||||||
|
|
|
@ -5,7 +5,6 @@ from config import config
|
||||||
from db import db
|
from db import db
|
||||||
import logging
|
import logging
|
||||||
from sendmail import sendmail
|
from sendmail import sendmail
|
||||||
from time import time
|
|
||||||
|
|
||||||
|
|
||||||
def shutdown():
|
def shutdown():
|
||||||
|
@ -16,8 +15,6 @@ def shutdown():
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
last_twitter_request = time()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
fh = logging.FileHandler('/var/log/ticketfrei/backend.log')
|
fh = logging.FileHandler('/var/log/ticketfrei/backend.log')
|
||||||
|
|
16
db.py
16
db.py
|
@ -141,6 +141,12 @@ class DB(object):
|
||||||
mail_date REAL,
|
mail_date REAL,
|
||||||
FOREIGN KEY(user_id) REFERENCES user(id)
|
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 cities (
|
CREATE TABLE IF NOT EXISTS cities (
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
user_id INTEGER,
|
user_id INTEGER,
|
||||||
|
@ -251,12 +257,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(
|
self.execute("INSERT INTO seen_telegrams (user_id, tg_id) VALUES (?, ?);", (uid, 0))
|
||||||
"INSERT INTO seen_telegrams (user_id, tg_id) VALUES (?, ?);", (uid, 0))
|
self.execute("INSERT INTO seen_mail (user_id, mail_date) VALUES (?, ?);", (uid, 0))
|
||||||
self.execute(
|
self.execute("INSERT INTO seen_tweets (user_id, tweet_id) VALUES (?, ?)", (uid, 0))
|
||||||
"INSERT INTO seen_mail (user_id, mail_date) VALUES (?, ?);", (uid, 0))
|
self.execute("INSERT INTO twitter_last_request (user_id, date) VALUES (?, ?)", (uid, 0))
|
||||||
self.execute("INSERT INTO seen_tweets (user_id, tweet_id) VALUES (?, ?)",
|
|
||||||
(uid, 0))
|
|
||||||
self.commit()
|
self.commit()
|
||||||
user = User(uid)
|
user = User(uid)
|
||||||
user.set_city(city)
|
user.set_city(city)
|
||||||
|
|
10
tfglobals.py
10
tfglobals.py
|
@ -1,10 +0,0 @@
|
||||||
from time import time
|
|
||||||
|
|
||||||
"""
|
|
||||||
This file is for shared global variables. They only stay during runtime.
|
|
||||||
|
|
||||||
For reference:
|
|
||||||
https://stackoverflow.com/questions/15959534/visibility-of-global-variables-in-imported-modules
|
|
||||||
"""
|
|
||||||
|
|
||||||
last_twitter_request = time()
|
|
10
user.py
10
user.py
|
@ -93,6 +93,16 @@ schlitz
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
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 get_telegram_credentials(self):
|
def get_telegram_credentials(self):
|
||||||
db.execute("""SELECT apikey
|
db.execute("""SELECT apikey
|
||||||
FROM telegram_accounts
|
FROM telegram_accounts
|
||||||
|
|
Loading…
Reference in a new issue