Created
November 29, 2011 21:38
-
-
Save armins/1406647 to your computer and use it in GitHub Desktop.
fetch air quality values from wien.gv.at - "Wiener Luftgüteindex"
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
| 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