我尝试运行一个简单的脚本,将流式直播推特。几次尝试过滤掉转发都没有成功。我的流中仍然有手动转发(文本为“RT@”)。 我尝试过其他方法,包括link和{a2}。在
在我学习的过程中,我的代码与以下代码非常相似:link
我该怎么做才能忽略转发?在
下面是我的代码片段:
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
您可以创建另一个函数来调用您的}内部。以下是对我有用的东西:
StreamListener
中的{结果如下:
^{pr2}$这不是最优雅的解决方案,但我相信它能解决您所面临的问题。在
相关问题 更多 >
编程相关推荐