Created
June 16, 2011 23:45
-
-
Save basicxman/1030579 to your computer and use it in GitHub Desktop.
A horrible script for Stack Overflow Growl notifications
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' | |
require 'json/pure' | |
require 'ruby-growl' | |
class StackOverflowNotifier | |
def initialize(*args) | |
@data = if File.exists? "data.json" | |
JSON.parse(File.read("data.json")) | |
else | |
{} | |
end | |
parse("http://stackoverflow.com/feeds/tag?tagnames=#{args.join("+")}&sort=newest") | |
write | |
end | |
def parse(page) | |
page = Nokogiri::XML(open(page)) | |
entries = page.css("entry") | |
entries.each do |entry| | |
url = entry.css("id").text | |
title = entry.css("title").text | |
notify(url, title) unless @data[url] | |
end | |
end | |
def write | |
File.open("data.json", "w") { |f| f.write(@data.to_json) } | |
end | |
def notify(url, title) | |
g = Growl.new("localhost", "ruby-growl", ["Stack Overflow Notification"]) | |
g.notify("Stack Overflow Notification", title, url) | |
`open #{url}` | |
@data[url] = title | |
end | |
end | |
File.open("so.log", "a") { |f| f.puts "Running on #{Time.now}" } | |
StackOverflowNotifier.new "ruby", "ruby-on-rails", "ruby-on-rails-3", "javascript" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment