Last active
September 4, 2015 13:35
-
-
Save cimm/330455 to your computer and use it in GitHub Desktop.
Gets the NMBS/SNCB trains leaving from a given station in Belgium.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'cgi' | |
require 'open-uri' | |
require 'hpricot' | |
current_time = Time.now.strftime("%H:%M") | |
url = "" | |
user_agent = "Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.253.0 Safari/532.5" | |
if Time.parse("17:00") < Time.now && Time.now < Time.parse("18:00") | |
railtime = Hpricot(open(url, "User-Agent" => user_agent)) | |
puts "Next trains leaving from Louvain-la-Neuve" | |
puts "" | |
trains = railtime.search("/html/body/form/table/tr") | |
trains.each do |train| | |
departure = train.search("td//a").inner_html | |
status = " " | |
if !train.search("td//i").empty? | |
status = "X" | |
end | |
detail = train.search("td[span]").inner_html.gsub(/<\/?[^>]*>/, "").gsub(/ /, " ") | |
puts "#{departure} #{status} #{detail}" | |
end | |
else | |
puts "Off" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment