How do I get an array of all users who retweeted a retweeted tweet using python3

python
tweepy

#1

How do I get an array of all users who retweeted a retweeted tweet using python3.

#!/usr/bin/python

#-----------------------------------------------------------------------
# twitter-retweets
#  - print who has retweeted tweets from a given user's timeline
#-----------------------------------------------------------------------

from twitter import *
import pymongo
from pymongo import MongoClient
import tweepy
import twitter
import json
import re


user=input("Enter the user for whom you want to extract people retweeting : ")

#-----------------------------------------------------------------------
# load our API credentials 
#-----------------------------------------------------------------------
CONSUMER_KEY = ' '
CONSUMER_SECRET = ' '
ACCESS_TOKEN = ' '
ACCESS_TOKEN_SECRET = ' '


#-----------------------------------------------------------------------
# create twitter API object
#-----------------------------------------------------------------------
twitter = Twitter(
                    auth = OAuth(ACCESS_TOKEN, ACCESS_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET))



#DataBase Connection
client = MongoClient()
db = client.tweet_User_db
tweet_collection = db.tweet_collection_RetweetUser
tweet_collection.create_index([("id", pymongo.ASCENDING)],unique = True) # make sure the collected tweets are unique

#-----------------------------------------------------------------------
# perform a basic search 
# twitter API docs: https://dev.twitter.com/rest/reference/get/statuses/user_timeline
#-----------------------------------------------------------------------




#-----------------------------------------------------------------------
# loop through each of my statuses, and print its content
#-----------------------------------------------------------------------


    results = twitter.statuses.user_timeline(screen_name = user)
    for status in results:
            if not ((str(status)).startswith('RT')):
                print (("@%s %s") % (user, status["text"]))
                tweet_collection.insert(status)
            
            #-----------------------------------------------------------------------
            # do a new query: who has RT'd this tweet?
            #-----------------------------------------------------------------------
                retweets = twitter.statuses.retweets._id(_id = status["id"])
                for retweet in retweets:
                        print ((" - retweeted by %s") % (retweet["user"]["screen_name"]))
                        #asdf=str(retweet)
                        #pat = re.compile(r"RT (\w+): ")
                        #x=pat.findall(asdf)
                        #print(("original author is %s" )%(x))
                        tweet_collection.insert(retweet)



#2

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.