Created
January 12, 2009 06:41
-
-
Save yosmoc/45912 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 | |
# -*- coding: utf-8 -*- | |
require 'pit' | |
require 'mechanize' | |
require 'ruby-growl' | |
require 'cgi' | |
$KCODE ='u' | |
conf = Pit.get('outputz.com', :require => { 'key' => 'please input your secret key!'}) | |
agent = Mechanize.new | |
agent.max_history = 1 | |
agent.get('http://outputz.com/daily') | |
agent.get(agent.page.links.find{ |l| l.href =~ /config/i}.href) | |
form = agent.page.forms.first | |
form['magic_word'] = conf['key'] | |
agent.submit(form) | |
unless agent.page.root.to_html =~ /#{conf['key']}/ | |
p 'lagin failed' | |
exit | |
end | |
agent.get('http://outputz.com/daily') | |
rank, info = agent.page.root.to_html.scan(%r!<p class="ranking">(\d+)(?:<span class="ranking_info">(.*?)</span>)?</p> | |
!).flatten | |
unless rank && info | |
p 'html parse failed!' | |
exit | |
end | |
info = CGI.unescapeHTML(info) | |
growl = Growl.new("localhost", "outputz notifier", ["outputz notifier"]) | |
growl.notify("outputz notifier", "this hour outputz rank.", rank+info , 0, true) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment