X-Git-Url: https://projects.mako.cc/source/twitter-api-cdsw-solutions/blobdiff_plain/1e2d406ccc7bfaa9c73ab809367ce5ae2ab6fc79..d4653b5f599083dc7631ff1a215096ac58b626d8:/solution-topics-5.py diff --git a/solution-topics-5.py b/solution-topics-5.py new file mode 100644 index 0000000..0371026 --- /dev/null +++ b/solution-topics-5.py @@ -0,0 +1,28 @@ +# For each original tweet, list the number of times you see it retweeted. + +import encoding_fix +import tweepy +from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET +import time + +auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) +auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) + +api = tweepy.API(auth) + +counter = 0 +for page in tweepy.Cursor(api.search, "community data", count=100).pages(): + counter = counter + len(page) + for tweet in page: + + # urls seem to be stored in tweet.entities["urls"] + for url in tweet.entities["urls"]: + print(url["expanded_url"]) + + # end this loop if we've gotten 1000 + if counter >= 1000: + break + + # This page suggests we can do one request every 5 seconds: + # https://dev.twitter.com/rest/reference/get/search/tweets + time.sleep(5)