Skip to content

Instantly share code, notes, and snippets.

@sanderversluys
Created June 26, 2012 08:04
Show Gist options
  • Save sanderversluys/2994283 to your computer and use it in GitHub Desktop.
Save sanderversluys/2994283 to your computer and use it in GitHub Desktop.
Twitter to csv export script
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