Skip to content

Instantly share code, notes, and snippets.

@skandhas
Created May 21, 2012 04:27
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 skandhas/2760557 to your computer and use it in GitHub Desktop.
Save skandhas/2760557 to your computer and use it in GitHub Desktop.
Fetch Ruby China nodes infomation.
#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