I'm trying to identify interesting people to follow on Twitter. To do this, I want to find users who post a tweet containing various keywords and then filter out users whose bios don't contain certain keywords.
I'm using the following code to identify the tweets, and then automatically follow the users who tweeted them:
naughty_words = ["example"]
good_words = ["example", "example"]
filter = " OR ".join(good_words)
blacklist = " -".join(naughty_words)
keywords = filter + blacklist
twitter = Twython(consumer_key, consumer_secret, access_token,
access_token_secret)
search_results = twitter.search(q=keywords, count=10)
try:
for tweet in search_results["statuses"]:
try:
st=tweet["entities"]["user_mentions"]
if st != []:
twitter.create_friendship(screen_name=st[0]["screen_name"])
except TwythonError as e:
print(e)
except TwythonError as e:
print(e)
This code is working great, but I want to filter my results more, as this method returns a lot of users that I don't want to follow! Does anyone know how I could amend this to include a second filter that looks at users' bios?