Created
October 16, 2018 15:56
-
-
Save vallantin/4118811411007867dc1b28dff0ce0f63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_save_tweets(filepath, api, query, max_tweets=1000000, lang='pt'): | |
tweetCount = 0 | |
#Open file and save tweets | |
with open(filepath, 'w') as f: | |
# Send the query | |
for tweet in tweepy.Cursor(api.search,q=query,lang=lang).items(max_tweets): | |
#Convert to JSON format | |
f.write(jsonpickle.encode(tweet._json, unpicklable=False) + '\n') | |
tweetCount += 1 | |
#Display how many tweets we have collected | |
print("Downloaded {0} tweets".format(tweetCount)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment