Grab retweeted status text in loop
Question: I am using the python script tweepy to scrape Twitter data; the scraped data
is output as a csv. The retweets are truncated. I am looking for suggestions
on how I could modify the code below to grab the "retweeted_status.text" if
the retweeted_status is "True". It seems that I have to specify:
"api.user_timeline(screen_name = screen_name,count=200,include_rts=True)"

    
    
    import sys
    from urllib.request import urlopen
    
    default_encoding = 'utf-8'
         if sys.getdefaultencoding() != default_encoding:
         reload(sys)
         sys.setdefaultencoding(default_encoding)
    
    import tweepy #https://github.com/tweepy/tweepy
    import csv
    
    #Twitter API credentials
    consumer_key = ""
    consumer_secret = ""
    access_key = ""
    access_secret = ""
    
    screenNamesList = [
    ''
    ]
    
    def get_all_tweets(screen_name):
    #Twitter only allows access to a users most recent 3240 tweets with    this method
    
    #authorize twitter, initialize tweepy
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_key, access_secret)
    api = tweepy.API(auth)
    
    #initialize a list to hold all the tweepy Tweets
    alltweets = []  
    
    #make initial request for most recent tweets (200 is the maximum allowed count)
    new_tweets = api.user_timeline(screen_name = screen_name,count=200)
    
    #save most recent tweets
    alltweets.extend(new_tweets)
    
    #save the id of the oldest tweet less one
    oldest = alltweets[-1].id - 1
    
    #keep grabbing tweets until there are no tweets left to grab
    while len(new_tweets) > 0:
        #print "getting tweets before %s" % (oldest)
    
        #all subsiquent requests use the max_id param to prevent duplicates
        new_tweets = api.user_timeline(screen_name =  screen_name,count=200,max_id=oldest)
    
        #save most recent tweets
        alltweets.extend(new_tweets)
    
        #update the id of the oldest tweet less one
        oldest = alltweets[-1].id - 1
    
        #print "...%s tweets downloaded so far" % (len(alltweets))
    
    #transform the tweepy tweets into a 2D array that will populate the csv 
    outtweets = [[tweet.id_str, tweet.created_at, tweet.text,  tweet.retweet_count, tweet.favorite_count, tweet.author.followers_count, tweet.author.description] for tweet in alltweets]
    
    #write the csv  
    
    with open('%s_tweets.csv' % screen_name, 'w', newline='',   encoding='utf-8-sig') as f:
        writer = csv.writer(f)
        writer.writerow(["id", "created_at", "text", "retweet_count","favorite_count", "followers_count", "description"])
        writer.writerows(outtweets)
    
    pass
    
    
    if __name__ == '__main__':   
    #pass in the username of the account you want to download
        for i, user in enumerate(screenNamesList):
            get_all_tweets(screenNamesList[i])
            i+=1
    


Answer: As you've discovered, the way Twitter handles retweets is a little strange.

In the JSON representation of the tweet you have something which looks like
this:

` - user: "you" - text: "RT @example this text gets truncated at the end of
the tw..." - retweeted: "true" - retweeted_status: - user: "example" - text:
"this text is the full text" `

So, look for `"retweeted":"true"` in the response. If it is there, grab the
tweet text from `status->retweeted_status->text`

