Last active
November 10, 2016 03:30
-
-
Save PeteFromGlasgow/9503632 to your computer and use it in GitHub Desktop.
WaniKani Gource Log Generation Script
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
<?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 = array("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