Create a gist now

Instantly share code, notes, and snippets.

#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'growl'
# Configuration
#
# URL to get questions from
# Newest => 'http://stackoverflow.com/questions?sort=newest'
# Ruby Tagged => 'http://stackoverflow.com/questions/tagged?tagnames=ruby&sort=newest'
# Ruby + RoR Tagged => 'http://stackoverflow.com/questions/tagged?tagnames=ruby+or+ruby-on-rails&sort=newest'
url = 'http://stackoverflow.com/questions/tagged?tagnames=ruby+or+ruby-on-rails&sort=newest'
# Refresh rate in seconds
refresh_rate = 120
# Sticky Growl notifications?
sticky_notification = false
# Code goes here
saved_questions = []
while true
begin
temp_questions = []
doc = Nokogiri::HTML(open(url))
doc.css('.question-summary').each do |question_div|
question_div.css('.summary h3 a').each do |link|
question_id = question_div.attributes['id'].to_s.split("-").last
temp_questions << question_id
unless saved_questions.include? question_id
#msg = "#{link.content} \n http://www.stackoverflow.com/questions/#{question_id}"
Growl.notify_ok link.content , :title => 'StackOverflow - New Question', :sticky => sticky_notification
end
end
end
saved_questions = temp_questions
sleep refresh_rate
rescue SystemExit, Interrupt
exit
rescue Exception => e
puts e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment