Skip to content

Instantly share code, notes, and snippets.

@nicinabox
Created October 16, 2011 23: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 nicinabox/1291603 to your computer and use it in GitHub Desktop.
Save nicinabox/1291603 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Created by _zsh for r/trees
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'growl'
subscribers = 0
TARGET = 123456
def scrape
open("http://www.reddit.com/r/trees") { |f| Hpricot(f) }
end
def find_subscribers doc, subscribers
count = (doc/".titlebox .number").inner_html.gsub(/,/, '').to_i
if count > subscribers
subscribers = count
notify subscribers
end
subscribers
end
def notify subscribers
Growl.notify {
self.title = "r/trees"
self.message = "#{subscribers} subscribers\n"
if subscribers == TARGET
sticky!
end
}
end
while subscribers != TARGET
doc = scrape
subscribers = find_subscribers doc, subscribers
sleep 30
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment