Skip to content

Instantly share code, notes, and snippets.

@hc5duke
Created July 12, 2009 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hc5duke/145534 to your computer and use it in GitHub Desktop.
Save hc5duke/145534 to your computer and use it in GitHub Desktop.
<?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