Created
October 6, 2012 06:23
-
-
Save i4fumi/3844213 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/ruby | |
# encoding: utf-8 | |
require 'rest_client' | |
require 'nokogiri' | |
def get_popularity(link) | |
doc = Nokogiri::HTML(RestClient.get "https://github.com#{link.attr(:href)}") | |
title = doc.css(".pagehead h1").first.content | |
unless title =~ /(.+) is the(?: #(\d+))? most popular language on GitHub/ | |
raise "parse error #{link}" | |
end | |
[$2.to_i, $1].tap { |rslt| p rslt } | |
end | |
def main | |
doc = Nokogiri::HTML(RestClient.get 'https://github.com/languages') | |
langs = doc.css(".all_languages a").map { |link| get_popularity(link) } | |
langs.sort_by(&:first).each do |popularity, lang| | |
popularity = 1 if popularity == 0 | |
if popularity < 51 | |
puts "<tr><td>#{popularity}</td><td>#{lang}</td></tr>" | |
else | |
print ", #{lang}" | |
end | |
end | |
print "\n" | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment