Created
February 11, 2018 02:43
-
-
Save yhuag/db2144b190e5d9dc73531ee9e8b9182e to your computer and use it in GitHub Desktop.
This file contains 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
import sys, codecs | |
if sys.version_info[0] < 3: | |
import got | |
else: | |
import got3 as got | |
def main(): | |
try: | |
tweetCriteria = got.manager.TweetCriteria().setQuerySearch('bitcoin').setSince("2015-01-01").setUntil("2015-12-31").setTopTweets(True) | |
outputFileName = "out-20150101-20151231.csv" | |
outputFile = codecs.open(outputFileName, "w+", "utf-8") | |
outputFile.write('username;date;retweets;favorites;text;geo;mentions;hashtags;id;permalink') | |
print('Searching...\n') | |
def receiveBuffer(tweets): | |
for t in tweets: | |
outputFile.write(('\n%s;%s;%d;%d;"%s";%s;%s;%s;"%s";%s' % (t.username, t.date.strftime("%Y-%m-%d %H:%M"), t.retweets, t.favorites, t.text, t.geo, t.mentions, t.hashtags, t.id, t.permalink))) | |
outputFile.flush() | |
# print('More %d saved on file...\n' % len(tweets)) | |
print(tweets[0].date) | |
tweets = got.manager.TweetManager.getTweets(tweetCriteria, receiveBuffer) | |
print('length of tweets: ', len(tweets)) | |
finally: | |
outputFile.close() | |
print('Done. Output file generated "%s".' % outputFileName) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment