Skip to content

Instantly share code, notes, and snippets.

@armins
Created November 29, 2011 21:38
Show Gist options
  • Save armins/1406647 to your computer and use it in GitHub Desktop.
Save armins/1406647 to your computer and use it in GitHub Desktop.
fetch air quality values from wien.gv.at - "Wiener Luftgüteindex"
require 'nokogiri'
require 'open-uri'
require "pp"
# real url
url = "https://www.wien.gv.at/ma22-lgb/luftsl.htm"
# testing url
local_url = 'luftguete.htm'
doc = Nokogiri::HTML(open(url))
timestamp = doc.css('table tbody tr').first.css('th').last.content
puts "timestamp: #{timestamp}"
description = Array.new
description[0] = ['Ozon', 'Feinstaub PM10', 'Stickstoffdioxid', 'Schwefeldioxid', 'Kohlemonoxid']
pp description
data = Hash.new
doc.css('table tbody tr').each do |line|
line_result = Array.new
location = line.css('td[align="left"]').first
unless location.nil?
location = location.content
end
line.css('td[align = "center"]').each do |cell|
line_result << (cell.keys.include?('title')? cell['title'] : nil)
end
unless line_result.empty?
data[location] = line_result
end
end
pp data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment