import tweepy
import dataset
from textblob import TextBlob
from sqlalchemy.exc import ProgrammingError
import pymysql
pymysql.install_as_MySQLdb()
from redis import Redis
from rq import Queue
q = Queue(connection = Redis())
class StreamListener(tweepy.StreamListener):
def on_status(self, status):
if status.retweeted:
return
text = status.text
blob = TextBlob(text)
sent = blob.sentiment
dictToInsert = dict(
text = text,
created = status.created_at,
id_str = status.id_str,
retweet_count = status.retweet_count,
polarity = sent.polarity,
subjectivity = sent.subjectivity,
)
table = db["KeyWordTest"]
try:
**result = q.enqueue(table.insert, dictToInsert)**
except ProgrammingError as err:
print(err)
我正在尝试流式传输并使用Redis Queue将它们插入到MySQL中,以便在程序无法快速处理时处理这些情况。
使用enqueue时遇到此错误。我认为原因是我只能放一个函数而不是table.function。但我不知道怎么能改写这个。