Created
September 25, 2013 18:22
-
-
Save swalberg/6703806 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'nokogiri' | |
require 'open-uri' | |
def to_minutes(string) | |
(hr, min) = string.split(/\s?:\s?/) | |
hr.to_i * 60 + min.to_i | |
end | |
doc = Nokogiri::HTML(open('http://www.wrha.mb.ca/wait-times/')) | |
time = doc.css('td.DateTime').inner_text | |
time = Time.parse(time) | |
puts time | |
doc.css('tr td span.Facility').each do |hospital| | |
row = hospital | |
row = row.parent while row.name != "tr" | |
(name, num_waiting, average_wait, _, longest_wait) = row.css('span').map(&:inner_text) | |
puts "#{time.strftime("%s")},\"#{name}\",#{num_waiting},#{to_minutes average_wait},#{to_minutes longest_wait}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment