Skip to content

Instantly share code, notes, and snippets.

@swalberg
Created September 25, 2013 18:22
Show Gist options
  • Save swalberg/6703806 to your computer and use it in GitHub Desktop.
Save swalberg/6703806 to your computer and use it in GitHub Desktop.
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