Skip to content

Instantly share code, notes, and snippets.

@yosmoc
Created January 12, 2009 06:41
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 yosmoc/45912 to your computer and use it in GitHub Desktop.
Save yosmoc/45912 to your computer and use it in GitHub Desktop.
#!/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