forked from ticketfrei/ticketfrei
Revert "crawl the username only once from twitter and save to db #45"
This reverts commit 9836ec7752
.
This commit is contained in:
parent
a89d1ce654
commit
ea95384a10
|
@ -50,11 +50,11 @@ class TwitterBot(Bot):
|
||||||
mentions = api.mentions_timeline(since_id=last_mention)
|
mentions = api.mentions_timeline(since_id=last_mention)
|
||||||
user.set_last_twitter_request(time())
|
user.set_last_twitter_request(time())
|
||||||
for status in mentions:
|
for status in mentions:
|
||||||
# don't retweet replies - only mentions.
|
|
||||||
if user.get_twitter_username() in status.extended_tweet.full_text:
|
|
||||||
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-_]+)",
|
||||||
"", status.extended_tweet.full_text)
|
"", status.text)
|
||||||
|
username = "@" + api.me().screen_name
|
||||||
|
if username in status.text:
|
||||||
reports.append(report.Report(status.author.screen_name,
|
reports.append(report.Report(status.author.screen_name,
|
||||||
self,
|
self,
|
||||||
text,
|
text,
|
||||||
|
|
1
db.py
1
db.py
|
@ -90,7 +90,6 @@ class DB(object):
|
||||||
user_id INTEGER,
|
user_id INTEGER,
|
||||||
client_id TEXT,
|
client_id TEXT,
|
||||||
client_secret TEXT,
|
client_secret TEXT,
|
||||||
screen_name TEXT,
|
|
||||||
active INTEGER,
|
active INTEGER,
|
||||||
FOREIGN KEY(user_id) REFERENCES user(id)
|
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||||
);
|
);
|
||||||
|
|
19
user.py
19
user.py
|
@ -3,7 +3,6 @@ from bottle import response
|
||||||
from db import db
|
from db import db
|
||||||
import jwt
|
import jwt
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
import tweepy
|
|
||||||
from pylibscrypt import scrypt_mcf, scrypt_mcf_check
|
from pylibscrypt import scrypt_mcf, scrypt_mcf_check
|
||||||
|
|
||||||
|
|
||||||
|
@ -268,15 +267,10 @@ schlitz
|
||||||
"oauth_token_secret": request_token[1]}
|
"oauth_token_secret": request_token[1]}
|
||||||
|
|
||||||
def save_twitter_token(self, access_token, access_token_secret):
|
def save_twitter_token(self, access_token, access_token_secret):
|
||||||
auth = tweepy.OAuthHandler(consumer_key=config['twitter']['consumer_key'],
|
db.execute("""INSERT INTO twitter_accounts(
|
||||||
consumer_secret=config['twitter']['consumer_secret'])
|
user_id, client_id, client_secret
|
||||||
auth.set_access_token(access_token, access_token_secret)
|
) VALUES(?, ?, ?);""",
|
||||||
api = tweepy.API(auth, wait_on_rate_limit=True)
|
(self.uid, access_token, access_token_secret))
|
||||||
username = api.me().screen_name
|
|
||||||
db.execute("""INSERT INTO (
|
|
||||||
user_id, client_id, client_secret, screen_name, active
|
|
||||||
) VALUES(?, ?, ?, ?, ?);""",
|
|
||||||
(self.uid, access_token, access_token_secret, username, 1))
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def get_twitter_token(self):
|
def get_twitter_token(self):
|
||||||
|
@ -292,11 +286,6 @@ schlitz
|
||||||
keys.append(row[1])
|
keys.append(row[1])
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
def get_twitter_username(self):
|
|
||||||
db.execute("SELECT screen_name FROM twitter_accounts WHERE user_id = ?",
|
|
||||||
(self.uid, ))
|
|
||||||
return db.fetchone()[0]
|
|
||||||
|
|
||||||
def update_telegram_key(self, apikey):
|
def update_telegram_key(self, apikey):
|
||||||
db.execute("UPDATE telegram_accounts SET apikey = ? WHERE user_id = ?;", (apikey, self.uid))
|
db.execute("UPDATE telegram_accounts SET apikey = ? WHERE user_id = ?;", (apikey, self.uid))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
Loading…
Reference in a new issue