Skip to content

Instantly share code, notes, and snippets.

@terrbear
Created May 25, 2015 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrbear/4df70bd16379b2eeca68 to your computer and use it in GitHub Desktop.
Save terrbear/4df70bd16379b2eeca68 to your computer and use it in GitHub Desktop.
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