Tag Archives: ruby

Ruby script to show the (Dutch) weather forecasts in your console

Just a quick ruby script to show the 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
  tr.xpath("td").each do |th|
    row << th.text
  table << row if row.count > 0

puts Hirb::Helpers::AutoTable.render table, :headers=>headers, :description=>false

The result in my ZSH (using theme agnoster) looks like this:


The birth of Lapsang

In my previous post I described a personal programming project I was planning. I wanted to use Ruby as the programming language of choice, but there are a couple of reasons for going back to C#: first, I couldn’t find a working GUI toolkit for Ruby (at least working on my OSX machine). I spent a full day and decided to move back to System.Windows.Forms (I can use the Mono implementation). Another reason is, as Michel already commented, a new language will slow me down too much and at this moment I prefer a working application above a new language.

The hardest part of a new project is the name and after a deep thought I came up with Lapsang (a black Chinese tea).

When downloading the data from the RSS-feed from HackerNews I saw there are only 25 items in the document. I need more items to train the network so I decided to make a quick-and-dirty screen scraper to browse the website and download the items of multiple pages. This will probably not be part of the final product, I prefer a pure RSS feed (or multiple, maybe via an OPML file) as my datasource.

My personal programming project


Lately I am following the newsfeed Hacker News (http://news.ycombinator.com) where members can post links to interesting (IT related) articles. There are a couple of new items per hour and members can vote these items up or down in the list. Not all articles are interesting for me and my time is limited so I must choose which articles to read. The site shows 30 items per page, only the title and the website it’s referring to and no description. Based on the title I select the most interesting items and open them in a new tab in the browser, read them and close the tabs and finally move on to the next page, etc.

A cunning plan

My idea is to make an application that can help me by suggesting interesting articles based on my previous selected items. Over time it should be better in giving suggestions. I finally have a reason to dive into neural networks. Ten years ago during my traineeship in Bangkok I worked in the Software and Language Laboratory of NECTEC and colleagues were working on Thai OCR and text-to-speech software using neural networks. I got fascinated but never found a reason to use it in my professional developer career.

I have been developing applications in C# for the last decade so it’s time for something new! The application will be build using Ruby, as this is a language that is on my ‘learning’-wishlist for a couple of years. I am not sure what libraries to use for the user interface yet. At home I use OSX and at work I use Windows and it would be nice if it runs on both platforms. I still having trouble getting wxRuby up-and-running at home so I will have a look at IronRuby in combination with Mono (WinForms) or maybe another cross-platform GUI toolkit.¬†At least this definitely is a reason to use a pattern like Model-View-Controller or Model-View-Presenter and make the UI layer as thin as possible.

The user interface will have a list of titles and a button to open a webbrowser with the selected article. I want to rate every title probably by dragging new items into one of three buckets/lists (must-read, maybe, not-worth-my-time) or by using 1-3 stars. The title and the score will be used in the learning part of the application. When the application downloads new items from the newsfeed, it will give a suggested score to each of them that should be visible to me (eg. colors, size, stars, sorted). First I will make it work, then I will make it beautiful.


This is a project with a lot of new things to learn (for me and for the application), but it is definitely a challenge :-)