Created
July 4, 2011 13:32
-
-
Save jamesu/1063338 to your computer and use it in GitHub Desktop.
Need to find the BEST project on github? This will help!
This file contains hidden or 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/env ruby | |
# hubscore | |
# Scores a project on github based on keyword metrics. | |
# Higher score = faster/in fashion. Lower score = slower/out of date. | |
# | |
# Usage: | |
# hubscore socketstream/socketstream | |
# | |
require 'rubygems' | |
require 'open-uri' | |
require 'nokogiri' | |
WORD_SCORE = { | |
'redis' => 20, | |
'experimental' => 20, | |
'rapid' => 10, | |
'rails' => -10, | |
'rack' => 10, | |
'node' => 20, | |
'php' => -10, | |
'cakephp' => 20, | |
'mvc' => 30, | |
'ruby' => -5, | |
'javascript' => 10, | |
'js' => 10, | |
'coffeescript' => 5, | |
'websockets' => 5, | |
'speed' => 10 | |
} | |
def score_project(name) | |
document = Nokogiri::HTML(open("https://www.github.com/#{name}")) rescue nil | |
if document.nil? | |
puts "Couldn't find project #{name}" | |
exit 0 | |
end | |
input = document.css('#readme').first.content rescue nil | |
if input.nil? | |
puts "Invalid project #{name}" | |
exit 0 | |
end | |
words = input.scan(/(\w+)/).map do |w| | |
(w[0]||'').downcase | |
end | |
score = 0 | |
words.compact.uniq.each do |word| | |
score += WORD_SCORE[word]||0 | |
end | |
score | |
end | |
if ARGV[0] | |
score = score_project(ARGV[0]) | |
puts "Score: #{score}" | |
else | |
puts "Usage: hubscore <user>/<project>" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nosql? of course!