Created
May 21, 2012 04:27
-
-
Save skandhas/2760557 to your computer and use it in GitHub Desktop.
Fetch Ruby China nodes infomation.
This file contains hidden or 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
#encoding:utf-8 | |
require "watir-webdriver" | |
def ruby_china_nodes_info | |
@browser = Watir::Browser.new | |
(1..49).inject([]) { |total,i| total << fetch_node_info(i)} | |
.sort_by{|_,topics| -topics } | |
.slice(0...30) | |
.tap { @browser.close } | |
end | |
def fetch_node_info(node_index) | |
@browser.goto "http://ruby-china.org/topics/node#{node_index}" | |
div = @browser.div(:id => 'node_info') | |
[ | |
div.h2.text, | |
div.span(:class =>'total').text =~/(\d+)/ ? ($1.to_i):0 | |
] | |
rescue | |
["Unkown node#{node_index}",0] | |
end | |
if __FILE__ == $0 | |
# for win32 console | |
STDOUT.set_encoding "gbk" | |
nodes_info = ruby_china_nodes_info | |
nodes_info.each {|node,topics| puts "#{node}:#{topics}" } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment