我想在Twython
搜索中排除转推(retweets)
和回复(replies)
。
这是我的代码:
from twython import Twython, TwythonError
app_key = "xxxx"
app_secret = "xxxx"
oauth_token = "xxxx"
oauth_token_secret = "xxxx"
naughty_words = [" -RT"]
good_words = ["search phrase", "another search phrase"]
filter = " OR ".join(good_words)
blacklist = " -".join(naughty_words)
keywords = filter + blacklist
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
search_results = twitter.search(q=keywords, count=100)
问题在于
-RT
功能实际上并没有起作用。编辑:
我已经尝试了 @forge 的建议,虽然它可以打印出非转推或回复的推文,但是当我将它们合并到下面的代码中时,机器人仍然会发现推文、转推、引用和回复。
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret) query = 'beer OR wine AND -filter:retweets AND -filter:replies'
response = twitter.search(q=query, count=100)
statuses = response['statuses']
try:
for tweet in statuses:
try:
twitter.retweet(id = tweet["id_str"])
except TwythonError as e:
print e
except TwythonError as e:
print e
有什么想法吗?是否有
filter:quotes
的过滤器?