Skip to content

Instantly share code, notes, and snippets.

@joannecheng
Last active December 18, 2015 12:59
Show Gist options
  • Save joannecheng/5786301 to your computer and use it in GitHub Desktop.
Save joannecheng/5786301 to your computer and use it in GitHub Desktop.
require 'json'
require 'httparty'
require 'sqlite3-ruby'
def get_trips(line)
url = "http://developer.mbta.com/lib/rthr/#{line}.json"
JSON.parse(HTTParty.get(url).body)
end
puts "start"
trips = []
['red', 'blue', 'orange'].each do |line|
get_trips(line)['TripList']['Trips'].each do |trip|
unless trip['Position'].nil?
position = trip['Position'].merge 'line' => line
trips << position
end
end
end
ScraperWiki::save_sqlite(unique_keys=trips[0].keys, data=trips)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment