Created
May 25, 2015 20:42
-
-
Save terrbear/4df70bd16379b2eeca68 to your computer and use it in GitHub Desktop.
This file contains 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' | |
URL = "http://www.wunderground.com/US/TX/173.html" #change this if you're not in cedar park | |
TIMESTAMP = /^\d\d\/\d\d\/\d\d\d\d/ | |
$seen = {} | |
def print(strings) | |
`say new update` | |
puts "-" * 80 | |
puts strings.join("\n") | |
puts "-" * 80 | |
puts | |
puts | |
$seen[strings.first] = true | |
end | |
def seen?(strings) | |
$seen[strings.first] | |
end | |
def fetch | |
doc = Nokogiri::HTML(`curl -s #{URL}`) | |
report = doc.css(".wx-module").detect{|el| el.to_s =~ /Local Storm Report/} | |
report = report.to_s.split("<br>").reject{|i| i.empty?} | |
buffer = [] | |
report.each do |line| | |
if line =~ TIMESTAMP | |
print(buffer) unless seen?(buffer) | |
buffer = [] | |
end | |
buffer << line | |
end | |
end | |
loop do | |
fetch | |
sleep 5 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment