Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Extract replies to a tweet into a CSV
import csv
import tweepy
# get credentials at
auth = tweepy.OAuthHandler('API Key', 'API Secret')
auth.set_access_token('Access Token', 'Access Token Secret')
api = tweepy.API(auth)
# update these for whatever tweet you want to process replies to
name = 'patrick_oshag'
tweet_id = '1101551802930077696'
for tweet in tweepy.Cursor(,q='to:'+name,result_type='recent',timeout=999999).items(1000):
if hasattr(tweet, 'in_reply_to_status_id_str'):
if (tweet.in_reply_to_status_id_str==tweet_id):
with open('replies_clean.csv', 'wb') as f:
csv_writer = csv.DictWriter(f, fieldnames=('user', 'text'))
for tweet in replies:
row = {'user': tweet.user.screen_name, 'text': tweet.text.encode('ascii', 'ignore').replace('\n', ' ')}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.