remove readme from the non-solutions
[twitter-api-cdsw-solutions] / solution-topics-5.py
1 # For each original tweet, list the number of times you see it retweeted.
2
3 import encoding_fix
4 import tweepy
5 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
6 import time
7
8 auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
9 auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
10
11 api = tweepy.API(auth)
12
13 counter = 0
14 for page in tweepy.Cursor(api.search, "community data", count=100).pages():
15     counter = counter + len(page)
16     for tweet in page:
17
18         # urls seem to be stored in tweet.entities["urls"]
19         for url in tweet.entities["urls"]:
20             print(url["expanded_url"])
21             
22     # end this loop if we've gotten 1000
23     if counter >= 1000:
24         break
25
26     # This page suggests we can do one request every 5 seconds:
27     # https://dev.twitter.com/rest/reference/get/search/tweets
28     time.sleep(5)

Benjamin Mako Hill || Want to submit a patch?