WaniKani scripters

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.

Somebody can give me some direction?

~Thanks

2 Likes

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.

4 Likes

This script has a pretty neat method. It downloads everything, puts it in an array, and then filters out only the items with the correct srs stage.

2 Likes

I took a look on the scrips code, but I don’t I can really figured out how and what.
Any of the writes here are active on the forum?

1 Like

this should roundabout work:

Code (untested)
	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.

Kumirei’s code is better though, much simpler:

1 Like

For just retrieving the items I would use this

wkof.include('ItemData');
wkof.ready('ItemData').then(fetch_items);

function fetch_items() {
  var config = {
    wk_items: {
      options: {
        assignments: true,
        include_hidden: true
      },
      filters: {
        item_type: 'voc',
        srs: '9'
      }
    }
  }
  wkof.ItemData.get_items(config).then(data=>callback));
}
3 Likes

I’m coding it in Java but oke.
When onResponse: I put your code, so when it fetches, it will filter the burned items out.

1 Like

Oh, if you can’t use WKOF then I suppose you could query https://api.wanikani.com/v2/assignments?burned=true&subject_types=vocabulary

2 Likes
  1. So I successfully read out the API, but how can I only read a single item.
  2. 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”,

jp

`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);
    }`
2 Likes

I don’t think you can read out a single random item via API, so just read out all of them, and choose a random one.

1 Like

Ah, oke. can you guide me a little bit how?

1 Like

You Guys have amazing Knowledge! What are SCRIPTS?, Please help me to learn

1 Like

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.

3 Likes

:face_vomiting:

5 Likes

Thanking you for your explaination

2 Likes

Is there another way. I mean ofcourse, I can use other back-end like Python, or use react native and node.js

1 Like

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.

1 Like

Yea, but this is a mobile app, and Java is used for native building. Ofcourse, finally if I’m better maybe I move to kotlin.

2 Likes

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!

1 Like

Bruh I’m so noob at code, only thing I know that it is less code. But for me I need to focus more one problem solving.

2 Likes