Skip to content

Instantly share code, notes, and snippets.

Created April 22, 2018 11:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Search for a Users Tweet on twitter
import tweepy
from custom_config import get_attr_from_list
from custom_config import consumer_key, consumer_secret, access_key, access_secret
def write_tweets_to_file(screen_name):
ids = []
x = 1
with open(screen_name.strip() + '.csv', 'w') as file:
for tweet in tweepy.Cursor(api.user_timeline, screen_name=screen_name).items():
line = ('%s | %s | %s | %s | %s | %s' % (tweet.created_at,
'' + str(,
'@' +,
get_attr_from_list(tweet.entities['hashtags'], 'text'),
tweet.text.replace('\n', "") # don't want new lines on csv
ids.append((, tweet.created_at))
print("%d. %s" % (x, line))
file.write(line + "\n")
x += 1
return ids
if __name__ == '__main__':
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
with open('screen_names.txt', 'r') as input:
for screen_name in input:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment