Reputation: 575
So I'm trying to search for tweets containing particular words in the Twitter API (tweepy wrapper). However, when searching for words, I'm getting close-to results. (i.e Search for "there" but tweepy returns "there's". Is there any way to specify with tweepy, the exact term that you want.
Part of my code:
otherTweet = tweepy.Cursor(api.search, q=word and hashtag, count=1, lang="en").items(1) # searches for words needed to retweet later
for a in otherTweet:
ref = a.text.encode("unicode-escape")
if "#" in ref and word not in ref.split(" ") or not otherTweet:
otherTweet = tweepy.Cursor(api.search, q=word, count=1, lang="en").items(1) # Can't find tweet with right hashtag.
print "got here"
word and hashtag are both variables, word = "hello" hashtag = "#blessed" for example. I'm assuming I do something to them to receive specific terms.
Upvotes: 0
Views: 1248
Reputation: 9270
In order to search for specific terms only, and remove any others you need to add whitespace around your search terms. Search for "there " or " there " instead of "there".
There's more complex routes, as in doing a secondary check for characters before and after, but this was the quickest and most useful route that I found in my application.
Upvotes: 0