【发布时间】:2021-01-18 23:56:31
【问题描述】:
我正在收集推特流并将其存储在一个 sqlite 数据库中。由于流即将到来并且数据库变得越来越大,我执行了一个命令来删除一分钟以上的推文。但推文只存在于数据库中越来越大。请帮忙,因为我是 sqlite 的新手
这是代码
class listener(StreamListener):
def on_data(self,data):
try:
data = json.loads(data)
tweet = unidecode(data['text'])
text = preprocess(tweet)
score = predict(text)['score']
created_at = data['created_at']
c.execute('INSERT INTO sentiment (created_at,tweet,score) VALUES (?,?,?)',(created_at,tweet,score))
conn.commit()
c.execute('DELETE FROM sentiment WHERE created_at IN(SELECT created_at FROM(SELECT
created_at, strftime("%s","now") - strftime("%s",created_at) AS passed_time FROM
sentiment WHERE passed_time >=60))')
conn.commit()
except Exception as e:
print(str(e))
【问题讨论】:
标签: python-3.x sqlite tweepy sentiment-analysis