Skip to content

Instantly share code, notes, and snippets.

@M0nica
Last active December 24, 2017 14:48
Show Gist options
  • Save M0nica/1ccc5716b189df683062d1cfb926d960 to your computer and use it in GitHub Desktop.
Save M0nica/1ccc5716b189df683062d1cfb926d960 to your computer and use it in GitHub Desktop.
A python script to search Twitter for #FreeCodeCamp and add recent Tweeters to a Twitter list.
import config
from twython import Twython, TwythonError
# create a Twython object by passing the necessary secret passwords
twitter = Twython(config.api_key, config.api_secret, config.access_token, config.token_secret)
# return tweets containing #FreeCodeCamp
response = twitter.search(q='"#FreeCodeCamp" -filter:retweets', result_type="recent", count=100)
# for each tweet returned from search of #FreeCodeCamp
for tweet in response['statuses']:
# print each username if needed for debugging
# print(tweet['user']['screen_name'])
# try to add each user who has tweeted the hashtag to the list
try:
twitter.add_list_member(slug='YOUR_LIST_SLUG', owner_screen_name='YOUR_SCREEN_NAME', screen_name= tweet['user']['screen_name'])
except TwythonError as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment