parent
2068b99b87
commit
5119c6bfbb
|
@ -5,6 +5,8 @@ import tweepy
|
|||
import re
|
||||
import requests
|
||||
import report
|
||||
import tfglobals
|
||||
from time import time
|
||||
from bot import Bot
|
||||
|
||||
|
||||
|
@ -27,6 +29,8 @@ class TwitterBot(Bot):
|
|||
:return: reports: (list of report.Report objects)
|
||||
"""
|
||||
reports = []
|
||||
if tfglobals.last_twitter_request + 60 > time():
|
||||
return reports
|
||||
try:
|
||||
api = self.get_api(user)
|
||||
except IndexError:
|
||||
|
@ -37,6 +41,7 @@ class TwitterBot(Bot):
|
|||
mentions = api.direct_messages()
|
||||
else:
|
||||
mentions = api.mentions_timeline(since_id=last_dm[0])
|
||||
tfglobals.last_twitter_request = time()
|
||||
for status in mentions:
|
||||
text = re.sub(
|
||||
"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
||||
|
|
|
@ -7,7 +7,7 @@ import requests
|
|||
from time import time
|
||||
import report
|
||||
from bot import Bot
|
||||
from backend import last_twitter_request
|
||||
import tfglobals
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -30,12 +30,14 @@ class TwitterBot(Bot):
|
|||
:return: reports: (list of report.Report objects)
|
||||
"""
|
||||
reports = []
|
||||
global last_twitter_request
|
||||
if last_twitter_request + 60 > time():
|
||||
#global last_twitter_request
|
||||
if tfglobals.last_twitter_request + 60 > time():
|
||||
return reports
|
||||
try:
|
||||
api = self.get_api(user)
|
||||
except Exception:
|
||||
except TypeError:
|
||||
# When there is no twitter account for this bot, we want to
|
||||
# seamlessly continue.
|
||||
#logger.error("Error Authenticating Twitter", exc_info=True)
|
||||
return reports
|
||||
last_mention = user.get_seen_tweet()
|
||||
|
@ -44,7 +46,7 @@ class TwitterBot(Bot):
|
|||
mentions = api.mentions_timeline()
|
||||
else:
|
||||
mentions = api.mentions_timeline(since_id=last_mention)
|
||||
last_twitter_request = time()
|
||||
tfglobals.last_twitter_request = time()
|
||||
for status in mentions:
|
||||
text = re.sub(
|
||||
"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
||||
|
|
3
tfglobals.py
Normal file
3
tfglobals.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from time import time
|
||||
|
||||
last_twitter_request = time()
|
16
user.py
16
user.py
|
@ -136,14 +136,6 @@ schlitz
|
|||
instance = db.cur.fetchone()
|
||||
return instance[1], instance[2], row[0], instance[0]
|
||||
|
||||
def get_twitter_credentials(self):
|
||||
keys = [config['twitter']['consumer_key'],
|
||||
config['twitter']['consumer_secret']]
|
||||
row = self.get_twitter_token()
|
||||
keys.append(row[0])
|
||||
keys.append(row[1])
|
||||
return keys
|
||||
|
||||
def toot_is_seen(self, toot_uri):
|
||||
db.execute("SELECT COUNT(*) FROM seen_toots WHERE user_id = ? AND toot_uri = ?;",
|
||||
(self.uid, toot_uri))
|
||||
|
@ -276,6 +268,14 @@ schlitz
|
|||
(self.uid, ))
|
||||
return db.cur.fetchone()
|
||||
|
||||
def get_twitter_credentials(self):
|
||||
keys = [config['twitter']['consumer_key'],
|
||||
config['twitter']['consumer_secret']]
|
||||
row = self.get_twitter_token()
|
||||
keys.append(row[0])
|
||||
keys.append(row[1])
|
||||
return keys
|
||||
|
||||
def update_telegram_key(self, apikey):
|
||||
db.execute("UPDATE telegram_accounts SET apikey = ? WHERE user_id = ?;", (apikey, self.uid))
|
||||
db.commit()
|
||||
|
|
Loading…
Reference in a new issue