Seattle Travel Times Web Service
With the closure of a number of I90 bridge lanes, I spent a lot of time waiting in and thinking about traffic.
The WSDOT has a Seattle Travel Times page that lists commute times between various cities in the Seattle area given the current traffic conditions. Unfortunately there wasn't any web service version of the data.
For the benefit of those wishing to build apps that use this data, I whipped up a REST web service that scrapes the data using Hpricot and formats it as JSON.
http://thebogles.com/berry/traffic/seattle/traveltimes.json gives all of the available travel times, formatted as JSON.
You can also specify optional "from" and "to" parameters to restrict the cities returned. An example: http://thebogles.com/berry/traffic/seattle/traveltimes.json?from=bellevue&to=seattle.
Implementation note: to make the JSON look pretty, I wanted an ordered hash. I'm still on Ruby 1.8, so I used the Ruby Facets class. The Dictionary class doesn't come with a to_json method, but it's easy to add one:
-
require 'facets/dictionary'
-
-
class Dictionary
-
def to_json(ignored=nil,ignored2=nil)
-
"{ " + self.map { |k,v| "#{k}: #{v.to_json}"}.join(', ') + "}"
-
end
-
end
1 Comment so far
Leave a comment
[…] You find the original post here thebogles.com/blog/2009/07/sea | philbo […]
By Seattle Travel Times Web Service | Seattle, WA Travel - Culture and Recreation on 08.08.09 5:20 pm
Leave a comment