Skip to content

Instantly share code, notes, and snippets.

@jeregrine
Forked from nickgartmann/Gemfile
Created June 24, 2014 15:30
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 jeregrine/244cb27f807768020dea to your computer and use it in GitHub Desktop.
Save jeregrine/244cb27f807768020dea to your computer and use it in GitHub Desktop.
gem 'rest-client', '~> 1.6.7'
gem 'nokogiri'
require 'nokogiri'
require 'rest-client'
require 'json'
task :repos, [:page_start, :page_end] do |t, args|
args.with_defaults(page_start: 1, page_end: 5)
GITHUB_SEARCH_P1 = "https://github.com/search?p="
GITHUB_SEARCH_P2 = "&q=\%22cordova.js\%22+in\%3Apath&ref=searchresults&type=Code&s=indexed"
threads = []
repos = []
(args[:page_start].to_i..args[:page_end].to_i).map do |page|
begin
Nokogiri::HTML(RestClient.get(GITHUB_SEARCH_P1 + page.to_s + GITHUB_SEARCH_P2)).css(".code-list-item .title a:first-child").each do |link|
threads << Thread.new {
href = link[:href]
begin
req = JSON.parse(RestClient.get("https://api.github.com/repos#{href}"))
repos << OpenStruct.new(
name: req["full_name"],
url: req["html_url"],
watchers: req["watchers_count"],
stars: req["stargazers_count"]
)
rescue
# Rate limited
end
}
end
rescue
# Rate limited
end
end
threads.each(&:join)
repos.sort{|a,b| (a.watchers + a.stars) <=> (b.watchers + b.stars) }.each do |repo|
puts repo.name
puts repo.url
puts "Stars: #{repo.stars}"
puts "Watchers: #{repo.watchers}\n\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment