Created
October 5, 2009 13:47
-
-
Save mislav/202132 to your computer and use it in GitHub Desktop.
Dump Twitter followers to JSON or CSV
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
# Usage: | |
# ruby -rubygems json2csv.rb my-dump.json > people.csv | |
# | |
require 'json'; require 'csv' | |
FIELDS = %w(id screen_name name friends_count followers_count) | |
data = JSON.load ARGF | |
csv = CSV::Writer.create(STDOUT) | |
data.each { |user| csv << FIELDS.map { |f| user[f] } } |
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
## Dump followers for twitter user to JSON string | |
# | |
# Usage: | |
# ruby -rubygems twitter-followers-json.rb mislav > followers-mislav.json | |
# | |
require 'open-uri'; require 'json' | |
users, cur = [], -1 | |
url = "http://twitter.com/statuses/followers/#{ARGV[0]}.json?cursor=%d" | |
until cur.zero? | |
data = JSON.load(open(url % cur)) | |
users.concat data['users'] | |
cur = data['next_cursor'].to_i | |
end | |
puts JSON.dump(users) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment