-
-
Save ouyangzhiping/1969941 to your computer and use it in GitHub Desktop.
Queries for the Languages on GitHub by Popularity
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/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