【发布时间】:2017-09-24 10:51:06
【问题描述】:
我正在尝试运行一个简单的脚本来流式传输实时推文。过滤掉转发的几次尝试均未成功。我仍然在我的信息流中收到手动转推(带有文本“RT @”)。 我尝试过其他方法,包括link 和link。
据我了解,我的代码与以下代码非常相似:link
我该怎么做才能忽略转发?
这是我的代码的 sn-p:
class StreamListener(tweepy.StreamListener):
def on_status(self, status):
if (status.retweeted) and ('RT @' not in status.text):
return
description = status.user.description
loc = status.user.location
text = status.text
coords = status.coordinates
geo = status.geo
name = status.user.screen_name
user_created = status.user.created_at
followers = status.user.followers_count
id_str = status.id_str
created = status.created_at
retweets = status.retweet_count
bg_color = status.user.profile_background_color
# Initialize TextBlob class on text of each tweet
# To get sentiment score from each class
blob = TextBlob(text)
sent = blob.sentiment
【问题讨论】:
-
status对象是什么样的? -
您的逻辑似乎有点混乱 -
(status.retweeted) and ('RT @' not in status.text)只会返回“官方”转推。也许您应该使用(status.retweeted) or ('RT @' in status.text)来排除“官方”和“手动”转推
标签: python python-3.x twitter tweepy