python 2.7 - How to increase number of search terms in Tweepy for Twitter API access? -
i found can include till 20+ search terms following code, gives me error of saying there many search terms. there way around it?
import tweepy searchterms = '1' or '2' or '3' # ... '99' or '100' tweets = tweepy.cursor(api.search, q=searchterms, since=startsince, until=enduntil).items()
per twitter docs, q
parameter limited.
a utf-8, url-encoded search query of 500 characters maximum, including operators. queries may additionally limited complexity.
if want build complex search term logic use streamer , listener. you're doing own filtering. here's simple example of listener. tried give popular objects returned on_status
method, returned json
.
import json class slistener(streamlistener): def __init__(self, api = none, fprefix = 'streamer'): self.api = api or api() self.counter = 0 self.fprefix = fprefix def on_data(self, data): elif 'limit' in data: if self.on_limit(json.loads(data)['limit']['track']) false: return false elif 'warning' in data: warning = json.loads(data)['warnings'] print warning['message'] return false def on_status(self, status): status_obj = json.loads(status) username = status_obj["user"]["screen_name"] userid = status_obj["user"]["id"] user_loc = status_obj["user"]["location"] tweet_date_time = status_obj["created_at"] tweetid = status_obj["id"] tweet = status_obj["text"].encode('utf-8') searchterms = ['1','2','3'] # ... '99' or '100' if any(query in tweet query in searchterms): print(tweet) #or
Comments
Post a Comment