diff --git a/twitter-api-example.py b/twitter-api-example.py index 27f0e154e4f36bf387a21c139dacd59f60c671cb..120cc0a1c84b8cafd54e5b270e35866b2585ad9b 100755 --- a/twitter-api-example.py +++ b/twitter-api-example.py @@ -12,22 +12,21 @@ logging.basicConfig(level=logging.INFO) def search(api, sincedate, untildate, csvFile, jsonFile): searchQuery = '((cota OR cotas OR universidade OR universidades) AND (racial OR raciais)) OR ((universidade OR universidades) AND (cota OR cotas))' - maxTweets = 10000000 - + tweetsPerQry = 100 # this is the max the API permits - + csvWriter = csv.writer(csvFile) - + # If results from a specific ID onwards are reqd, set since_id to that ID. # else default to no lower limit, go as far back as API allows sinceId = None - + # If results only below a specific ID are, set max_id to that ID. # else default to no upper limit, start from the most recent tweet matching the search query. # Python3 has 9223372036854775807 as max number max_id = sys.maxsize - + tweetCount = 0 print("Downloading max {0} tweets".format(maxTweets)) while tweetCount < maxTweets: @@ -65,22 +64,22 @@ def search(api, sincedate, untildate, csvFile, jsonFile): print("Downloaded {0} tweets".format(tweetCount)) max_id = new_tweets[-1].id except tweepy.TweepError as e: - print("some error : " + str(e)) + print("some error: " + str(e)) continue - + print ("Downloaded {0} tweets".format(tweetCount)) if __name__ == "__main__": ####input your credentials here - consumer_key = 'pcn6szyFLVnzxDclKazZ3tQPI' - consumer_secret = 'OGKptAjYnoh33mvPEkBPQgcApNXFysbCUx2CjQwjtHhr7Z9unO' - access_token = '1127995977963646977-vqZMlKE8vJLSFMWmL6J9ouEZBncPi1' - access_token_secret = 'xT6WMGkUZJULIMAwpG0AUWtOFYDdGMBYAFSHUZIo9NLYh' - + consumer_key = '' + consumer_secret = '' + access_token = '' + access_token_secret = '' + auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) - + if( len(sys.argv) != 5): print("Usage "+sys.argv[0]+" <since date yyyy-mm-dd> <until date yyyy-mm-dd> <csv File> <json File>") sys.exit(1)