Search term intersection and union using Python Tweepy

試著忘記壹切 提交于 2019-12-02 09:12:40

问题


I would like to get the tweets that either contain 'love' and/or '#hate' using Python Tweepy. But using my current code as below, it only returns the first term (i.e. 'love'). I have been trying for days to debug and read the Tweepy/Twitter documentation to no avail. Please advice.

import tweepy
import time

ckey = ""
csecret = ""
atoken = ""
asecret = ""

OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret,
    'access_token_key':atoken, 'access_token_secret':asecret}
auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)

for tweet in tweepy.Cursor(api.search, q=('love' or '#hate'), since='2014-09-15', until='2014-09-16').items(500): 
    try:

        print "Tweet created:", tweet.created_at
        print "Tweet:", tweet.text.encode('utf8')

        counter += 1

    except IOError:
        time.sleep(60)
        continue

回答1:


From looking at the twitter API documentation, the 'or' should be capitalized and should be inside the single quotes:

q = ('love OR #hate')

https://dev.twitter.com/rest/public/search



来源:https://stackoverflow.com/questions/25878188/search-term-intersection-and-union-using-python-tweepy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!