Skip to content

Instantly share code, notes, and snippets.

@mcdickenson
Created March 2, 2019 14:59
Show Gist options
  • Select an option

  • Save mcdickenson/c5f73f50bbd95fdcbe44d62b514cbbd0 to your computer and use it in GitHub Desktop.

Select an option

Save mcdickenson/c5f73f50bbd95fdcbe44d62b514cbbd0 to your computer and use it in GitHub Desktop.

Revisions

  1. mcdickenson created this gist Mar 2, 2019.
    26 changes: 26 additions & 0 deletions get_replies.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    import csv
    import tweepy

    # get credentials at developer.twitter.com
    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'

    replies=[]
    for tweet in tweepy.Cursor(api.search,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):
    replies.append(tweet)

    with open('replies_clean.csv', 'wb') as f:
    csv_writer = csv.DictWriter(f, fieldnames=('user', 'text'))
    csv_writer.writeheader()
    for tweet in replies:
    row = {'user': tweet.user.screen_name, 'text': tweet.text.encode('ascii', 'ignore').replace('\n', ' ')}
    csv_writer.writerow(row)