Skip to content

Instantly share code, notes, and snippets.

@davetroy
Created August 28, 2012 19:29
Show Gist options
  • Save davetroy/3503065 to your computer and use it in GitHub Desktop.
Save davetroy/3503065 to your computer and use it in GitHub Desktop.
Parse tweets from baltimore.twittervision.com
require 'rubygems'
require 'yajl'
require 'fastercsv'
tweetfile = ARGV[0]
PARSER = Yajl::Parser.new
def output_tweet(s)
if s['geo']
lat = s['geo']['coordinates'][0]
lon = s['geo']['coordinates'][1]
elsif s['coordinates']
lat = s['coordinates']['coordinates'][1]
lon = s['coordinates']['coordinates'][0]
end
return unless lat && lon
csv_tweet = [s['user']['screen_name'],s['text'],lat,lon].to_csv
puts csv_tweet
end
PARSER.on_parse_complete = method(:output_tweet)
PARSER.parse(File.read(tweetfile))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment