Created
August 28, 2012 19:29
-
-
Save davetroy/3503065 to your computer and use it in GitHub Desktop.
Parse tweets from baltimore.twittervision.com
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
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