Last active
September 21, 2020 16:06
-
-
Save virtalas/60cee44ec0e2a6226e43107b319ef899 to your computer and use it in GitHub Desktop.
Export word list from Yomiwa iOS app, convert to tab-separated file, and import to Anki. Add example sentences by adding the word first, then by pressing analyze text and starring it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # Export word list from Yomiwa iOS app, convert to tab-separated file, and import to Anki. | |
| # Add example sentences by adding the word first, then by pressing analyze text and starring it. | |
| skip = 0 | |
| word_count = 0 | |
| to_write = '' | |
| reading_meanings = False # Expect meanings in the next line | |
| expecting_sentence = False # Expect an example sentence in the next non empty line (has to be added after the word in Yomiwa iOS app) | |
| tag = 'Yomiwa\n' | |
| with open('anki.txt') as f: | |
| for line in f: | |
| if skip > 0: | |
| skip -= 1 | |
| continue | |
| if line.startswith('Yomiwa'): | |
| continue | |
| if line.endswith(':\n'): | |
| skip += 1 | |
| continue | |
| # Reading a new word begins | |
| if '【' in line: | |
| if to_write.endswith(', '): | |
| # There was no example sentence, clear last colon from meanings | |
| to_write = to_write[:-2] | |
| # Add empty field in place of example sentence | |
| to_write += '\t' + '\t' + tag | |
| to_write += '\n' | |
| splitted = line.split(' 【') | |
| vocab_kanji = splitted[0] | |
| vocab_higarana = splitted[1].split('】')[0] | |
| to_write += vocab_kanji + '\t' + vocab_higarana + '\t' | |
| reading_meanings = True | |
| word_count += 1 | |
| continue | |
| if reading_meanings and line != '\n': | |
| # Add a meaning line with no \n and add a colon | |
| to_write += line.rstrip() + ', ' | |
| continue | |
| elif reading_meanings and line == '\n': | |
| # No more meanigs to read. Next (after empty line) might be an example sentence. | |
| reading_meanings = False | |
| expecting_sentence = True | |
| continue | |
| elif expecting_sentence and line != '\n': | |
| # Add example sentence | |
| expecting_sentence = False | |
| if to_write.endswith(', '): | |
| to_write = to_write[:-2] | |
| to_write += '\t' + line.rstrip() + '\t' + tag | |
| f = open("import_to_anki.txt", "w") | |
| f.write(to_write) | |
| f.close() | |
| print(str(word_count) + ' words exported to import_to_anki.txt') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment