Skip to content

Instantly share code, notes, and snippets.

@ouyangzhiping
Forked from benbjohnson/top_github_lang.rb
Created March 4, 2012 01:54
Show Gist options
  • Save ouyangzhiping/1969941 to your computer and use it in GitHub Desktop.
Save ouyangzhiping/1969941 to your computer and use it in GitHub Desktop.
Queries for the Languages on GitHub by Popularity
#!/usr/bin/ruby
require 'rubygems'
require 'mechanize'
mechanize = Mechanize.new
rankings = {}
# Retrieve language list
mechanize.get("https://github.com/languages") do |page|
page.parser.css('div.all_languages li a').each do |a|
lang_name = a.text.strip
next if lang_name == 'Max/MSP'
print '.'
# Retrieve ranking
mechanize.get("https://github.com#{a['href']}") do |page|
match = page.parser.at_css('div.pagehead h1').text.match(/#(\d+)/)
rank = match.nil? ? 1 : match[1].to_i
rankings[rank] = lang_name
end
end
end
puts
puts
rankings.keys.sort.each do |rank|
puts "#{rank}. #{rankings[rank]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment