Created
November 16, 2012 18:47
-
-
Save bwillis/4089834 to your computer and use it in GitHub Desktop.
Retrieve a Github project's Stargazers meta data
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/env ruby | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
class GithubStargazers | |
def initialize(repo) | |
@repo = repo | |
end | |
def by_followers | |
page = 1 | |
users = [] | |
begin | |
doc = Nokogiri::HTML open("https://github.com/#{@repo}/stargazers?page=#{page}") | |
usernames = doc.css("ul.members li>a").collect { |link| link.attr("href").gsub("/","") } | |
page = doc.css("div.pagination").children[1].attr("href") ? page + 1 : nil | |
users += usernames.collect do |username| | |
user_doc = Nokogiri::HTML open("https://github.com/#{username}") | |
followers = user_doc.at_css("ul.stats>li>a>strong").text.to_i | |
stars = 0 | |
user_doc.css("ul.repo-stats li.stargazers>a").each { |repo_stars| stars += repo_stars.text.to_i } | |
{:name => username, :followers => followers, :stars => stars} | |
end | |
end while page | |
users.sort! { |a,b| influence(b) <=> influence(a) } | |
end | |
def influence(user) | |
user[:followers] | |
end | |
end | |
stargazers = GithubStargazers.new("bwillis/versioncake").by_followers | |
stargazers.each do |stargazer| | |
puts "#{stargazer[:name]}: followers: #{stargazer[:followers]}, github: https://github.com/#{stargazer[:name]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment