Wanikani Open Framework [developer thread]

Thanks for reposting here. I’ll be sure to see it when I start working on my bug/update list.

1 Like

@rfindley I just noticed that there’s a refresh_on_change option for settings in WKOF. You might want to document that a bit better, as it’s only mentioned under on_refresh

Thanks, I’ll add it to the list!

1 Like

Thank you for your hard work, @rfindley. I used the framework to quickly generate production clozes for Anki from context sentences up to my last cleared level. The pipe delimited "C"SV ends up in a variable called ‘giant’.

var giant = "";
function cleanString( x ) {
  return x.replace( /[\n]/g, " " ).replace( /\s+/g, " " ).trim();
}
wkof.ItemData.get_items({wk_items:{filters:{level:"1..-1", item_type: "voc"}}}).then(function(items){
//wkof.ItemData.get_items({wk_items:{filters:{level:"1", item_type: "voc"}}}).then(function(items){
    items.forEach(function(item) {
        item.data.context_sentences.forEach(function(cs) {
            let clozeText = "英:".concat( cleanString( cs["en"] ), "<br/>日:", cleanString( cs["ja"] ) );
            let cleanSlug = cleanString( item.data.slug );
            // strip okurigana - thank you terrancesnyder @ github
            let clozeSlug = cleanString( item.data.characters.replace( /[^一-龯]+$/g, "" ) );
            let slugRegex = new RegExp( clozeSlug, "g" );
            let slugMatches = [ ... clozeText.matchAll( slugRegex ) ];
            if( slugMatches.length ) {
              let slugMatch = slugMatches[ Math.floor( Math.random() * slugMatches.length ) ];
              // slugMatch["length"] seems to be consistently 1 regardless of what it matches?
              clozeText = clozeText.substring( 0, slugMatch[ "index" ] ).concat( "{{c1::", slugMatch[0], "}}", clozeText.substring( slugMatch["index"] + slugMatch[0].length ) );
              giant = giant.concat( cleanSlug, "|", clozeText, "|#level", item.data.level, "\n" );
            }
        })
    })
    console.log( "done" );
});

2 Likes

If you request items with ItemData.get_items you can use -1 in the SRS filter (for locked items), however, when you use ItemData.get_index to sort by SRS it does not include a -1 entry. Is this intentional?

I think the -1 may have been added to the filters later, and just wasn’t added to the index functions.

I think I see a way to change it for the index function without too much trouble if it’s something you’d be interested in.

I’ll have to think about the impact on existing scripts, though. I’m not sure how many scripters are using the get_index() functions.

1 Like

I see. I didn’t really need it to be an entry this time, since I was just fetching locked and initiate items, so it’s fine if you don’t want to add it. However, I did expect it to work, for what that’s worth.

Is this correct for the filters:
-1 = locked
0 = unlocked but lesson not done

?

1 Like

Yes! I believe that’s right

1 Like

I think you’re right… it should be consistent between the two. I’ll wait a few days to see if I get any feedback in this thread, though I doubt most scripters are watching this thread in the same way as the APIv2 thread.

I will probably need a reminder to get back to this, though. So if you happen to remember, please ping be again.

1 Like

Fixed!

I updated get_index() for both ‘srs_stage’ and ‘srs_stage_name’.

1 Like

Thanks!

1 Like

Was reading this new feature (wiping local storage after seven days of inactivity) for WebKit. I think the framework runs off of Indexed DB? Don’t know how it’ll affect the framework. Just wanted to give a heads up.

6 Likes

Well, time for WebKit to also implement “vacation mode” :rofl:

1 Like

Thanks for the heads-up!

Fortunately, it sounds like data doesn’t get wiped if the user uses the site within 7 days.
If someone goes longer than that, Open Framework will auto-repopulate its data, including API key. So, you may see a small up-tick in WK API usage. Probably not enough to notice, but if you guys have any issues, let me know.

Do you think this is a good idea?

1 Like

I suppose it would be best to follow Wanikani’s convention on how SRS stages are named (…if they continue to be named, which I assume they will).

1 Like

Did you miss the SRS announcement on June 17th? Due to adding multiple SRS systems with possibly varying numbers of categories, all names will be dropped.

I saw it, but I only skimmed the announcement since I’ve been neck-deep in project deadlines.

I had noticed that the stage names were not in the new API endpoint, but (as Viet said) I know they are fond of naming things – which is also a good thing for usability – so I hadn’t considered that they might discontinue the names.

I’ll still stick to my statement, though: It’s probably best to follow Wanikani’s convention. If they don’t plan to support names, then we (scripters) would likely be setting ourselves up for some headaches down the road if we try to sustain the names in the Framework and scripts. For example, new users will be confused as to what the names are referring to. And if, at some point, a future SRS stage-numbering system doesn’t align cleanly with the current names, then it will be an even messier cleanup.

3 Likes

It makes sense why you would want to do that! They definitely do seem like they plan to do something like that “future… numbering system”

1 Like