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

Add anki decks #89

Merged
merged 3 commits into from
Sep 14, 2020
Merged
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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ If you have any suggestions, feedback, questions, or bugs to report, feel free t
### Resources for Studying Japanese

##### Tools
- [Anki - SRS Flashcard App](https://apps.ankiweb.net/) (great for memorizing vocab)
- [Anki - SRS Flashcard App](https://apps.ankiweb.net/) (great for memorizing vocab, decks matching this repo are available [here](resources/tools/decks) )
- [Jisho - Online Japanese Dictionary](http://jisho.org/) (extremely useful for looking up words, kanji, etc.)
- [KanjiTomo - Japanese OCR Program](https://www.kanjitomo.net/) (very useful for reading manga, LNs, etc.)

Expand All @@ -83,7 +83,7 @@ The following resources were used in this project. I couldn't have done it witho
- [easytimer.js](https://github.com/albert-gonzalez/easytimer.js) for the super easy timer.
- [Kanji Canvas](https://github.com/asdfjkl/kanjicanvas) for the stroke order exercises.
- [Noto CJK](https://www.google.com/get/noto/help/cjk/) and [Sawarabi Gothic](https://fonts.google.com/specimen/Sawarabi+Gothic) for the fonts used in the Hiragana/Katakana stroke order exercises.

- [Genanki](https://github.com/kerrickstaley/genanki) for the simple package to create Anki decks

### Donate
Please see the [Donate page](https://sethclydesdale.github.io/genki-study-resources/donate/) for ways to support my work.
18 changes: 17 additions & 1 deletion resources/tools/about-this-folder.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,20 @@ Return value usage example: `{おはよう||width:70}`
Checks for duplicate entries in the dictionary so that they can either be merged or removed. Execute this script in the console while viewing the [dictionary](https://sethclydesdale.github.io/genki-study-resources/lessons/appendix/dictionary/) to check for any dupes.

Considering how huge it is, we may end up making duplicate entries from time to time. So this script helps ensure the dictionary word count stays accurate, while delegating the tedious job of checking to robots!



### anki_decks_maker.py
* Requires python 3.6+ with the [genanki](https://pypi.org/project/genanki) pkg installed

Create [Anki](https://apps.ankiweb.net/) flashcards decks to memorise vocabulary,
each card that is created is tagged with it's lesson number, type, and category (e.g Lesson_1, Vocabulary, Family)

```shell script
python3 anki_decks_maker.py <path_to_lessons_folder>

# For example:
python3 anki_decks_maker.py ../../lessons-3rd
python3 anki_decks_maker.py ../../lessons
```

All of the decks created are currently available under the `decks` folder
87 changes: 87 additions & 0 deletions resources/tools/anki_decks_maker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import re
import ast
import sys
from pathlib import Path

import genanki

lessons_folder = Path(sys.argv[1])
title_regex = re.compile(r'<title>(.*):(.*)- Lesson')
quizlet_regex = re.compile(r'quizlet : (.*?})', flags=re.S)
output_folder = Path('.').absolute().joinpath('decks').joinpath(lessons_folder.name)


def get_tags(html):
"""
<title>Useful Expressions: Time (Minutes 11-30) - Lesson 1 | Genki ...</title>
Useful_Expressions , Time_(Minutes_11-30)
"""
match = title_regex.search(html)
return match.group(1).strip().replace(' ', '_'), match.group(2).strip().replace(' ', '_')


def get_vocab(html):
return ast.literal_eval(quizlet_regex.search(html).group(1).replace(r'//', '#'))


def main():
output_folder.mkdir(parents=True, exist_ok=False)

my_model = genanki.Model(
1607392319,
'Simple Model',
fields=[
{'name': 'Question'},
{'name': 'Answer'},
],
templates=[
{
'name': 'Card',
'qfmt': '{{Question}}',
'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
},
],
css="""
.card {
font-size: 48px;
text-align: center;
}""")

combined_deck = genanki.Deck(
1810167044, # Random hardcoded id
f'Genki')
combined_deck.add_model(my_model)

decks = [combined_deck]
for lesson_folder in lessons_folder.glob('lesson*'):
lesson_number = lesson_folder.name.split('-')[-1]

my_deck = genanki.Deck(
1810167044 + int(lesson_number), # Random hardcoded id
f'Genki lesson {lesson_number}')
my_deck.add_model(my_model)
decks.append(my_deck)

for vocab_folder in lesson_folder.glob('vocab*'):
with open(vocab_folder.joinpath('index.html')) as f:
html = f.read()
tags = get_tags(html)
try:
vocab = get_vocab(html)
except Exception:
print(f'Failed parsing of lesson-{lesson_number}, vocab file {vocab_folder}')
continue
for jp, eng in vocab.items():
note = genanki.Note(model=my_model,
fields=[jp, eng],
tags=['Genki', f'lesson-{lesson_number}', *tags])
my_deck.add_note(note)
combined_deck.add_note(note)

for deck in decks:
if deck.notes:
genanki.Package(deck).write_to_file(output_folder.joinpath(f'{deck.name.replace(" ", "_")}.apkg'))


if __name__ == '__main__':
main()
Binary file added resources/tools/decks/lessons-3rd/Genki.apkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki.apkg
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_1.apkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_2.apkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_3.apkg
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_4.apkg
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_5.apkg
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_6.apkg
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_7.apkg
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_8.apkg
Binary file not shown.
Binary file added resources/tools/decks/lessons/Genki_lesson_9.apkg
Binary file not shown.