Created
August 19, 2016 22:13
-
-
Save EddM/76523d14ae2c9d81003adbf8f474f743 to your computer and use it in GitHub Desktop.
quickly display your critical kanji/vocab from wanikani
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 | |
require "httparty" | |
API_KEY = "abc123" | |
THRESHOLD = 80 | |
response = HTTParty.get("https://www.wanikani.com/api/user/#{API_KEY}/critical-items/#{THRESHOLD}") | |
data = JSON.parse(response.body) | |
items = data["requested_information"] | |
items.group_by { |item| item["type"] }.each do |group, items| | |
puts "\n============ #{group} ============\n\n" | |
items.sort_by { |i| i["percentage"].to_i }.reverse.each do |item| | |
character = item["character"] | |
kana = item["kana"] | |
meaning = item["meaning"] | |
if item.has_key? "important_reading" | |
readings = [] | |
readings << "#{item["onyomi"]} (on)" if item["onyomi"] && item["onyomi"] != "N/A" | |
readings << "#{item["kunyomi"]} (kun)" if item["kunyomi"] && item["kunyomi"] != "N/A" | |
readings << "#{item["nanori"]} (na)" if item["nanori"] && item["nanori"] != "N/A" | |
printf " %-4s %-28s %s\n", character, meaning[0..27], readings.join(" ") | |
elsif kana | |
charljustmax = 12 | |
kanaljustmax = 14 | |
character = character.ljust(charljustmax - character.size) | |
kana = kana.ljust(kanaljustmax - kana.size) | |
printf " %s %s %s\n", character, kana, meaning | |
else | |
printf " %-4s %s\n", character, meaning | |
end | |
end | |
end | |
puts "\n#{items.size} Critical Items\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment