Skip to content

Instantly share code, notes, and snippets.

@xldenis
Created January 20, 2014 15:03
Show Gist options
  • Save xldenis/8521405 to your computer and use it in GitHub Desktop.
Save xldenis/8521405 to your computer and use it in GitHub Desktop.
Script that generates graduation years and language information from a CSV containing relevant fields for McHacks. Replace username and password with real username/password combination to be able to use the authenticated github API ratelimit.
require 'octokit'
require 'csv'
require 'faraday-http-cache'
stack = Faraday::Builder.new do |builder|
builder.use Faraday::HttpCache
builder.use Octokit::Response::RaiseError
builder.adapter Faraday.default_adapter
end
Octokit.middleware = stack
f = File.open("output.txt","w+")
csv = CSV.read("gistfile1.txt", { headers: true, header_converters: :symbol})
grad_years = csv[:graduation_year].group_by(&:to_s).map {|i,j| [i,j.count]}
github = csv[:github].map {|i| i.split("/")[-1].downcase}.reject {|i| i.length <= 1 || (i.include? "." ) || (i.include? "none")}
user_map = Hash[(csv[:first_name].zip csv[:last_name]).map {|i,j| i+" "+j}.zip github]
f.puts grad_years
api = Octokit::Client.new :login =>'username', :password =>'password'
p api.rate_limit.remaining
total_repos = {}
p "Looking up repos"
user_map.each_with_index do |(name,url),index|
total_repos[name] = api.repositories url rescue ""
p index if index % 10 == 0
end
p "computing languages"
languages = total_repos.map {|n,r| {n =>r.map(&:language)}}.reduce(&:merge)
condensed_lang = languages.map {|n,l| {n => (l.group_by(&:to_s).values.max_by(&:length).first unless (l.nil? || l.empty?)) }}.reduce(&:merge)
p "outputing"
f.puts condensed_lang.inspect
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment