Created
June 17, 2012 16:17
-
-
Save ttscoff/2944985 to your computer and use it in GitHub Desktop.
Readability stats for passed text using ipeirotis.appspot.com
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/env ruby | |
# Uses the Readability Metrics API from http://ipeirotis.appspot.com/readability-api.html | |
# Accepts text from STDIN (piped) or as an argument | |
=begin examples | |
pbpaste|text_score.rb # copy text and run (on OS X) to get the stats for the clipboard. | |
cat myfile.md|text_score.rb # get scores for the contents of a file | |
=end | |
require 'open-uri' | |
require 'net/http' | |
require 'json' | |
input = STDIN.stat.size > 0 ? STDIN.read : ARGV.join | |
res = Net::HTTP.post_form(URI.parse("http://ipeirotis.appspot.com/readability/GetReadabilityScores"),{'format'=>'json', 'text'=>input}) | |
if res.code.to_i == 200 | |
json = JSON.parse(res.body) | |
puts "Characters: " + json['characters'].to_s | |
puts "Words: " + json['words'].to_s | |
puts "Sentences: " + json['sentences'].to_s | |
puts "Syllables: " + json['syllables'].to_s | |
puts "Complex words: " + json['complexwords'].to_s | |
puts "Gunning-Fog: " + json['gunningfog'].to_s | |
puts "ARI: " + json['ari'].to_s | |
puts "Coleman Liau: " + json['colemanliau'].to_s | |
puts "Flesch Kincaid: " + json['fleschkincaid'].to_s | |
puts "Flesch Reading: " + json['fleschreading'].to_s | |
puts "Smog: " + json['smog'].to_s | |
puts "Smog Index: " + json['smogindex'].to_s | |
else | |
puts "Error: " + res.code | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment