I have tried to pull the number of apprentice items from the WK API but the numbers never seem to match what my dashboard says on the WK website or Tsurukame on iOS. Those appear to correct yet my figure is much less (54 vs 37).
What I am doing is accessing assignments.srs_stage (‘https://api.wanikani.com/v2/assignments/’) and counting the number of srs_stage entries with numbers from 1 to 4 (0 = lessons, 1-4 = apprentice ‘as far as I know’).
Has something changed recently to throw this way of access off? I checked the code in the lesson cap userscript and that appears to use the same method and also brings back the wrong results.
Any advice on getting accurate apprentice level numbers would be greatly appreciated.
By default, the Open Framework filters out items that WK has hidden (i.e. removed from being taught). Maybe that explains the difference? If you are using wkof.ItemData.get_items(), try passing the option to include_hidden, and see if that makes a difference.
And doing so in Excel/Apple shortcuts… That would be interesting. I’ve not done much external linking in Excel.
It’s amazing how far spreadsheet software has come, especially considering that spreadsheets were one of the earliest general applications in the history of computing. To still retain so much of their original form is nothing short of mind-boggling.
Thank you it’s a bit scary as a complete beginner but I’m sure I can create some great productivity scripts if I succeed.
Right, I’ve managed to do it in Excel Power Query!
I’ll have to try later on today to make it into an Apple Shortcut but it will just be a case of converting the syntax. If I can’t do that I’m sure I can make a Python script to run from a Shorcut.
For anyone looking to get this information and tackle API pagination through power query, please see below code:
let
// you can change the url here based on what you want to recieve, see api docs here: https://docs.api.wanikani.com/20170710/
api_url = "https://api.wanikani.com/v2/assignments/",
// replace KEY with your api token from this url: https://www.wanikani.com/settings/personal_access_tokens
api_key = "KEY",
headers = [Headers=[Authorization="Bearer " & api_key]],
// first page url and data
initReq = Json.Document(Web.Contents(api_url , headers)),
initData = initReq[data],
// gather and cycle through pages after page 1
gather = (data as list, url) =>
let
newUrl = Json.Document(Web.Contents(url, headers))[pages][next_url],
newReq = Json.Document(Web.Contents(newUrl, headers)),
newdata = newReq[data],
data = List.Combine({data, newdata}),
check = if newReq[pages][next_url] = null then data else @gather(data, newUrl)
in check,
// group all data from pages together
outputList = gather(initData, api_url),
// expand all data
#"expand data" = Table.FromRecords(outputList),
#"remove other columns" = Table.SelectColumns(#"expand data",{"data"}),
// filter to srs and apprentice items only
#"expand srs_stage" = Table.ExpandRecordColumn(#"remove other columns", "data", {"srs_stage"}, {"srs_stage"}),
#"filter to apprentice items only" = Table.SelectRows(#"expand srs_stage", each [srs_stage] >= 1 and [srs_stage] <= 4),
// count apprentice items and return as value
#"count apprentice items" = Table.RowCount(#"filter to apprentice items only")
in
#"count apprentice items"
Yeah this seems similar to what I ended up doing, I had to create some kind of loop to keep finding the next page url, storing the data as a list and expand all.
It’s the first time I’ve tried something like that but it seems to work perfectly now.
I might try and recreate it in Python as a learning exercise at some point.
I’ve had a play around and managed to create this script in Apple Shortcuts. It isn’t the most elegant of solutions but I’m very happy with the result.