Created
October 16, 2011 23:42
-
-
Save nicinabox/1291603 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
#!/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