Created
June 24, 2014 14:45
-
-
Save nickgartmann/751f3f58ad78d2605ac1 to your computer and use it in GitHub Desktop.
Rake task to grab recently updated cordova projects from github
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
gem 'rest-client', '~> 1.6.7' | |
gem 'nokogiri' |
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
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
Usage: