Skip to content

Instantly share code, notes, and snippets.

@cimm cimm/train.rb
Last active Sep 4, 2015

What would you like to do?
Gets the NMBS/SNCB trains leaving from a given station in Belgium.
#!/usr/bin/env ruby
require 'rubygems'
require 'cgi'
require 'open-uri'
require 'hpricot'
current_time ="%H:%M")
url = ""
user_agent = "Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/ Safari/532.5"
if Time.parse("17:00") < && < Time.parse("18:00")
railtime = Hpricot(open(url, "User-Agent" => user_agent))
puts "Next trains leaving from Louvain-la-Neuve"
puts ""
trains ="/html/body/form/table/tr")
trains.each do |train|
departure ="td//a").inner_html
status = " "
if !"td//i").empty?
status = "X"
detail ="td[span]").inner_html.gsub(/<\/?[^>]*>/, "").gsub(/&nbsp;/, " ")
puts "#{departure} #{status} #{detail}"
puts "Off"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.