Created
July 12, 2009 05:24
-
-
Save hc5duke/145534 to your computer and use it in GitHub Desktop.
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" | |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > | |
<head> | |
<title>Bart</title> | |
<style type="text/css" media="screen"> | |
div {max-width:300px;} | |
div.destination {font-size:24px;font-weight:bold;border:2px solid #00c;text-align:center;margin:0px -2px;} | |
div.estimates {padding-bottom:15px;} | |
div.good {background-color:#8d8;} | |
div.ignore {opacity:0.3;} | |
div.opposite {opacity:0.7; background-color:#f88;} | |
span.red {color:#c00;font-weight:bold;} | |
</style> | |
</head> | |
<body> | |
<% | |
require 'rubygems' | |
require 'open-uri' | |
require 'hpricot' | |
require 'json' | |
cars = {} | |
#doc = Hpricot(open("http://www.bart.gov/dev/eta/bart_eta.xml")) | |
doc = Hpricot(open("bart_eta.xml")) | |
list = ["DUBL", "EMBR"] | |
["EMBR", "MONT", "CIVC", "POWL"].each do |station| | |
dest = {:DUBL => "", :EMBR => ""} | |
(doc/"station").each do |s| | |
abbr = (s/'abbr').inner_html | |
if list.include?(abbr) | |
(s/"eta").each do |e| | |
dest= (e/"destination").inner_html | |
time = (e/"estimate").inner_html.split(',').map &:strip #.map{|t|} | |
cars[abbr] ||= {} | |
cars[abbr][dest] = time | |
# puts "cars[#{abbr}][#{dest}] = #{time.to_json}<br/>" | |
end | |
end | |
end | |
end | |
cars.each do |c| | |
puts "#{c.to_json}<hr/>" | |
end | |
%> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment