Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes in words and definitions handler, updated readme #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Export Kindle Vocabulary Builder to Anki APKG

ATTENTION!!!
If you encounter trouble running the script, try using nodejs v10.0 version, then remove node_modules folder and try again. It worked for me, hope it will work for you as well.
Also if dict.db file is empty (weights around 8KB), or despite taking some more space Anki flashcards are deprived of definitions from the dictionary of your choice, then open the .rawml file and createDictDatabase.js, find what separates definitions (for me it was opening h2 tag), and also look what is after the word, for me it was (no surprise) closing h2 tag. Then change the values in createDictDatabase.js file for those which suits your needs.

![](./kindle_anki.png)

[Vocabulary Builder](https://www.amazon.com/gp/help/customer/display.html?nodeId=201733850) is one of my favorite features on Kindle. With a tap on the word, it pops up a window displaying definitions and at the same time creates a flashcard in the background. What's more, it saves the sentences where the word appreares, which makes it easier to remember words. However, E-Ink is not ideal for frequent paging, and it seems that Vocabulary Builder doesn't have an algorithm on tracking forgeting curve.
Expand Down
9 changes: 7 additions & 2 deletions createAPKG.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ const createAPKG = ({ vocab, dict }) => {
card: {
fields: ['word', 'meaning', 'usage'],
template: {
question: '{{word}}',
question: '<h2>{{word}}</h2><p><i>{{usage}}</i></p>',
answer: `
<div class="word">{{word}}</div>
<div class="word"><h2>{{word}}</h2></div>
<div class="meaning">{{meaning}}</div>
<div class="usage">{{usage}}</div>
<style>
.meaning{
text-align:left;
}
</style>
`
}
}
Expand Down
26 changes: 17 additions & 9 deletions createDictDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,33 @@ function createDictDatabase({ input: rawml, output: database }) {
const db = new Database(database)
db.exec('CREATE TABLE dictionary(word text, meaning text)')

//I will introduce some changes there

const src = createReadStream(rawml)
src
.pipe(new Separator({ separator: '<hr/>' }))
.pipe(new Separator({ separator: '<h2>' }))
.on('data', chunk => {
let html = chunk.toString().trim()
let $ = cheerio.load(html)
let $word = $('word')

//let $word = $('word')

let $word = html.substring(0, html.indexOf("</h2>") - 1)
html = html.substring(html.indexOf("</h2>")+6)
if (!$word.length) {
return
}

let words = $word
.map((_, word) => {
word = $(word)
word.find('sup').remove()
return word.text().replace(/,?\s*$/, '')
})
.get()
//let words = $word
// .map((_, word) => {
// word = $(word)
// word.find('sup').remove()
// return word.text().replace(/,?\s*$/, '')
// })
// .get()

let words = new Array();
words.push($word);
const sql = `INSERT INTO dictionary (word, meaning) VALUES (
'${doubleQuote(words.join('|'))}',
'${doubleQuote(html)}')`
Expand Down