Skip to content

Instantly share code, notes, and snippets.

@Marak
Created October 3, 2010 19:58
Show Gist options
  • Select an option

  • Save Marak/608869 to your computer and use it in GitHub Desktop.

Select an option

Save Marak/608869 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
require 'yaml'
require 'cgi'
require 'bossman'
include BOSSMan
require 'igraph'
require 'net/http'
# Lengthen timeout in Net::HTTP
module Net
class HTTP
alias old_initialize initialize
def initialize(*args)
old_initialize(*args)
@read_timeout = 5*60 # 5 minutes
end
end
end
$stdout.sync = true
puts "Getting URLs"
BOSSMan.application_id = YAML.load_file("config.yml")['yahookey']
offset = 0
done = false
urls = []
while !done
results = BOSSMan::Search.web('site:github.com location "' + ARGV[0] + '" "profile - github"', :start => offset)
offset += results.count.to_i
if offset > results.totalhits.to_i
done = true
end
urls += results.results.map { |r| r.url }
end
# this will become the graph
next_v_id = 1
v_to_id = { }
id_to_v = { }
edges = [ ]
puts "Getting social graph"
graph = {}
Net::HTTP.start('github.com') { |http|
for line in urls
sleep 1
line.match(/github.com\/([a-zA-Z0-9-]+)/)
me = $1
if me.match(/^(.*)\/$/)
me = $1
end
url = "/api/v2/yaml/user/show/#{me}/followers"
puts url
req = Net::HTTP::Get.new(url)
response = http.request(req)
case response
when Net::HTTPSuccess
graph[me] = []
for link in YAML.load(response.body)["users"]
graph[me] << link
#puts "\"#{me}\",\"#{link}\""
# add this link to the graph
v_arr = [me, link]
v_arr.each do |cur_v|
if v_to_id[cur_v]
cur_id = v_to_id[cur_v]
else
cur_id = next_v_id
v_to_id[cur_v] = cur_id
id_to_v[cur_id] = cur_v
next_v_id = next_v_id + 1
end
edges.push(cur_id)
end
end
else
puts "non-200: #{me}"
end
end
}
#build the graph and do some processing
g = IGraph.new(edges,true)
vs = g.vertices
#max = vs.zip(g.degree(vs,IGraph::ALL,true)).max{|a,b| a[1] <=> b[1]}
#puts "Maximum degree is #{sprintf("%10i",max[1])}, vertex #{max[0]}, id #{id_to_v[max[0]]}."
#
#max = vs.zip(g.closeness(vs,IGraph::ALL)).max{|a,b| a[1] <=> b[1]}
#puts "Maximum closeness is #{sprintf("%10f",max[1])}, vertex #{max[0]}, id #{id_to_v[max[0]]}."
max = vs.zip(g.betweenness(vs,IGraph::ALL)).max{|a,b| a[1] <=> b[1]}
puts "Maximum betweenness is #{sprintf("%10f",max[1])}, vertex #{max[0]}, id #{id_to_v[max[0]]}."
sorted_list = vs.zip(g.betweenness(vs,IGraph::ALL)).sort{|a,b| b[1] <=> a[1]}
for i in (1..20)
puts "##{i}: #{id_to_v[sorted_list[i-1][0]]}"
end
@takinbo
Copy link
Copy Markdown

takinbo commented Oct 5, 2010

I get this error when I try to run the script on my machine:

/usr/lib/ruby/gems/1.8/gems/bossman-0.4.1/lib/bossman/boss.rb:10:in `initialize': undefined method `to_query' for #<Hash:0x7f1629826270> (NoMethodError)
    from /usr/lib/ruby/gems/1.8/gems/bossman-0.4.1/lib/bossman/search.rb:12:in `new'
    from /usr/lib/ruby/gems/1.8/gems/bossman-0.4.1/lib/bossman/search.rb:12:in `method_missing'
    from ./clout.rb:34

@christianchristensen
Copy link
Copy Markdown

http://stackoverflow.com/questions/4014180/exception-with-method-to-query-missing

I think that addresses the to_query problem - I believe that method is in the Rails gem.

@takinbo
Copy link
Copy Markdown

takinbo commented Dec 9, 2010

Thanks Chris, it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment