Created
October 3, 2010 19:58
-
-
Save Marak/608869 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/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 |
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.
Thanks Chris, it worked.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get this error when I try to run the script on my machine: