I successfully read-out the API from WaniKani, but I want to ask those who have more experience with building Wani Kani scripts.
How can I read out the burned vocabulary, and I don’t want the API to spit all vocabulary on me, I only want the burned vocabulary.
So, when I click on the button, one random chosen burned vocabulary will be displayed.
I don’t know anything about writing scripts myself, but I do know there is a script that adds a button to the dashboard that lets you review random Burn items.
So maybe that does what you’re looking for, or you can at least look through the code that they used.
wkof.include('ItemData');
wkof.ready('ItemData').then(getItems).then(mapItemsToSrs).then(showRandomBurned);
function getItems() {
return wkof.ItemData.get_items(config);
//return wkof.ItemData.get_items(config).then(filterToActiveAssignments);
}
function getSrsStage(assignments) {
if (!assignments) {
return 0; // not yet learned
}
return assignments.srs_stage;
}
function mapItemsToSrs(items) {
let itemsBySrs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].reduce((result, srs) => { // stage 0 = not yet learned
result[srs] = [];
return result;
}, {});
// separation by srs stage may be necessary in future if we want to show kanji learned per SRS stage etc.
items.forEach(function(item) {
let srsStage = getSrsStage(item.assignments);
if (srsStage == 9 && item.object == 'vocabulary') { // 9 = burned
itemsBySrs[srsStage].push(item);
itemsBySrs.totalVocab++;
}
});
return itemsBySrs;
}
function showRandomBurned(items) {
let totalBurnedVocab = itemsBySrs[9].length;
let randomItem = itemsBySrs[9][4]; // 9 = burned. 4 was determined to be random by dice roll
// do stuff with it
}
obviously you use a smarter random function, that checks the length/number of burned items.
It’s adapted and simplified from my Show Number of Learned Kanji, Vocabulary script,
which adapts and simplifies the code from the SRS and Leech breakdown script mentioned.
It could be further simplified, but i don’t know what data you may need.
So I successfully read out the API, but how can I only read a single item.
Also, I want to go deeper, so I can read only the burned vocab. So: “requested_information”: [
{
“level”: 1,
“character”: “一”,
“kana”: “いち”,
“meaning”: “one”, “user_specific”: { “srs”: “burned”,
`private void sendRequestAndPrintResponse() {
String url = "https://www.wanikani.com/api/user/18287822e799e86b4ad2cbdd068e85d9/vocabulary/1";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("requested_information");
for(int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
// Append character to textView here
String cha = jsonObject.getString("character");
vocab.append(cha);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(request);
}`
Starting from your code, assuming it works like that already:
// Append character to textView here
JSONArray jsonArray = response.getJSONArray("requested_information");
ArrayList<String> characters = new ArrayList<String>();
for(int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
// Append character to textView here
String cha = jsonObject.getString("character");
characters.push(cha);
}
Random rand = new Random(); // set up our random number generator
int numberOfChars = characters.length;
// Generate random integer in range 0 to number of characters - 1
int randomCharacterIndex = rand.nextInt(characters.length); // boundary is exclusive
String randomCharacter = characters.get(randomCharacterIndex);
vocab.append(randomCharacter);
Note: i didn’t test this, and it’s been a while since i coded in Java.
Scripts are (relatively) simple and short pieces of software code, usually in a single file, which is the difference to software code in general (usually more files, more complex). Though there are a few pretty complex scripts for Wanikani.
In the context of the Wanikani, userscripts modify the Wanikani website to show you more information, give you better controls, etc.
But in this thread, we’re actually talking about Software Code (making programs) external to Wanikani, in this case to show you random burned vocabulary items in an external program for you to review.
For a web project with a web API like Wanikani, i guess it has some advantages using web frameworks/languages (js, node.js, react). Also, Web skills are more and more in demand. But if you can do what you want to do with Java, why not.
I love Kotlin, it’s also more concise than Java, and i think it’s relatively easy to transition from Java. We had a mobile development course in college, and they asked us to do at least a small part of our Android app in Kotlin, but we liked it so much we decided to do the whole app in Kotlin.
Just try doing a few classes in Kotlin, it’s interoperable with Java. You’ll like it. Take a look at data classes, bye bye getters and setters!