Created
June 26, 2012 08:04
-
-
Save sanderversluys/2994283 to your computer and use it in GitHub Desktop.
Twitter to csv export script
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 json | |
import urllib2 | |
import unicodecsv | |
user = "ifsorbuts" | |
count = 100 | |
output = "tweets.csv" | |
feed = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&screen_name={0}&count={1}".format(user, count) | |
allowed_keys = ["id", "text", "created_at"] | |
tweets = json.load(urllib2.urlopen(feed)) | |
file = open(output, 'wb') | |
writer = unicodecsv.writer(file, encoding='utf-8') | |
for tweet in tweets: | |
row = [] | |
for key in allowed_keys: | |
if key in tweet: | |
row.append(tweet[key]) | |
writer.writerow(row) | |
print "Exported {0} tweets to {1}".format(len(tweets), output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment