Ruby script to show the weather forecasts in your console
Just a quick ruby script to show the Dutch weather forecasts for next week using the html screen scraping gem nokogiri and a table formatter gem called hirb.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'hirb'
table = []
headers = []
page = Nokogiri::HTML(open("http://knmi.nl/waarschuwingen_en_verwachtingen/"))
page.css(".realtable")[0].xpath("tr").each do |tr|
row = []
tr.xpath("th").each do |th|
headers << th.text
end
tr.xpath("td").each do |th|
row << th.text
end
table << row if row.count > 0
end
puts Hirb::Helpers::AutoTable.render table, :headers=>headers, :description=>false
The result in my ZSH (using theme agnoster) looks like this: