Skip to content

Instantly share code, notes, and snippets.

@kaidesu
Forked from PeteFromGlasgow/gist:9503632
Last active August 29, 2015 14:07
Show Gist options
  • Save kaidesu/564505b1f2d0d3cc792b to your computer and use it in GitHub Desktop.
Save kaidesu/564505b1f2d0d3cc792b to your computer and use it in GitHub Desktop.
<?php
/*
* Calls the WaniKani API and generates a custom log compatible with gource.
*/
function curlcon($url)
{
$key = "";
$url = "https://www.wanikani.com/api/v1.2/user/$key/$url";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // this line makes it work under https
curl_setopt($ch, CURLOPT_HEADER, false); // return headers or not.
$buffer = curl_exec($ch);
return json_decode($buffer);
}
$colours = ["kanji" => "DD0093", "vocabulary" => "882D9E", "radicals" => "0093DD", "burned" => "434343"];
$kanji = curlcon("kanji");
$radicals = curlcon("radicals");
$vocabulary = curlcon("vocabulary");
$output = [];
$username = $kanji->user_information->username;
foreach ($kanji->requested_information as $number => $kanjiObj) {
$character = $kanjiObj->character;
$level = $kanjiObj->level;
$unlockDate = $kanjiObj->user_specific->unlocked_date;
$burnedDate = $kanjiObj->user_specific->burned_date;
if ($unlockDate != null) {
$output[] = "$unlockDate|$username|A|kanji/$character|".$colours['kanji']."\n";
if ($burnedDate !== 0) {
$output[] = "$burnedDate|$username|M|kanji/$character|".$colours['burned']."\n";
}
}
}
foreach ($radicals->requested_information as $number => $kanjiObj) {
$character = $kanjiObj->meaning;
$level = $kanjiObj->level;
$unlockDate = $kanjiObj->user_specific->unlocked_date;
$burnedDate = $kanjiObj->user_specific->burned_date;
if ($unlockDate != null) {
$output[] = "$unlockDate|$username|A|radicals/$character|".$colours['radicals']."\n";
if ($burnedDate !== 0) {
$output[] = "$burnedDate|$username|M|radicals/$character|".$colours['burned']."\n";
}
}
}
foreach ($vocabulary->requested_information->general as $number => $kanjiObj) {
$character = $kanjiObj->character;
$level = $kanjiObj->level;
$unlockDate = $kanjiObj->user_specific->unlocked_date;
$burnedDate = $kanjiObj->user_specific->burned_date;
if ($unlockDate != null) {
$output[] = "$unlockDate|$username|A|vocabulary/$character|".$colours['vocabulary']."\n";
if ($burnedDate !== 0) {
$output[] = "$burnedDate|$username|M|vocabulary/$character|".$colours['burned']."\n";
}
}
}
uasort($output, function($a,$b){
$obj1 = explode("|", $a);
$obj2 = explode("|", $b);
if ($obj1[0] == $obj2[0]) {
return 0;
}
return ($obj1[0] < $obj2[0]) ? -1 : 1;
});
foreach ($output as $key => $value) {
echo $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment