Is there a Context Sentences export script?

I’ve searched around this part of forum, and also on TamperMonkey. Is there an API script that will export the WK context sentences?

1 Like

If you send me an email at kumi@kumirei.com I can reply with a CSV of the sentences

2 Likes

GET /WK-example-sentences.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: @Kumirei
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

5 Likes
import axios from 'axios'

export const wkApi = axios.create({
  baseURL: 'https://api.wanikani.com/v2/',
  headers: {
    Authorization: `Bearer ${process.env.WANIKANI_API_KEY}`
  }
})

export async function getVocab () {
  const allData: any[] = []
  let nextUrl = '/subjects'

  while (true) {
    const r = await wkApi.get(nextUrl, {
      params: {
        types: 'vocabulary'
      }
    })

    console.log(r.data.url)

    allData.push(
      ...r.data.data.map((d) => ({
        sentences: d.data.context_sentences
      }))
    )

    nextUrl = r.data.pages.next_url || ''
    if (!nextUrl) {
      break
    }
  }

  return allData
}
1 Like

Hi,

How do you run that little piece of code?

It would be nice to have those context sentences spoken. tbh, they are still way to difficult for me to read. I do a dance when I can actually read one!

1 Like

What OS are you using? Do you have a programming language installed?

Furthermore, do you need a sound file, or can you open a browser (you can try this)?

1 Like

This should work, and you can run with nothing installed.

https://repl.it/repls/FreshWhitesmokeCustomers

1 Like

hi,

I opened the bit you posted on here and in a new chrome tab and it’s not too happy with me!


I’m happy to install anything really. I’d even rather install something! I run win10 and the only installed stuff I have is anaconda with all the data analysis stuff. And R.
Can’t do axios with those.

I’m very curious about all these scripts. I’d like to learn more.

1 Like

Can you run Python / Requests?

Axios is NodeJS.

You will have to edit Repl.it, if you want to run it.

1 Like

Oh my, I feel like I derailed this post.

WKPython

Had a quick look on stackexchange but I’m really unfamiliar with this. I don’t script much in my life!

It defo gets stuck at the axios. I gather I need something extra in there.

1 Like

Just use the code from repl.it, but you would have to edit this line.

const WANIKANI_API_KEY = ''

I am not giving my key.

About import axios from 'axios', it’s a special JavaScript code, that usually cannot be run directly. It needs special compiler, e.g. Babel, tsc. You will have to stick with require() if you don’t want to install stuff.

2 Likes

Put the wrong number in the first time. It ran this time.

I will look into installing extra stuff.

Tx a lot for spending all this time helping me out. xx

1 Like

I just installed this and it worked beautifully. Incidentally I tried it on eating natto for breakfast every morning… Never tried natto but can’t say it looks appetising!

I feel like I owe natto a try now.

1 Like