Git Product home page Git Product logo

anki_deck's Introduction

anki_deck

anki_deck is a simple tool to generate Anki flashcards from the xdxf dictionaries.

Based on https://www.reddit.com/r/Anki/comments/34imaw/export_from_goldendict_to_anki_deck_working_method/

To use anki_deck you need the following data:

  • XDXF dictionary file.

  • Words file - list of words you want to put in flashcards. It's just a plain file with one word per line:

    someword
    another
    
  • Audio samples (optional) in .ogg format.

anki_deck can create plain text flashcards file or .apkg deck. Both of them may be imported by Anki. To import text file you will need to create a card with fields and deck .apkg may be imported without extra actions.

You may use it without install like:

python -m anki_deck.cli ....

Or install with setyp.py and use:

anki_deck ...

Usage:

# To generate flashcards text file
anki_deck -d /<path>/<to>/dict.xdxf -a /<path>/<to>/audio -w mywords.txt txt

# To generate a deck
anki_deck -d /<path>/<to>/dict.xdxf -a /<path>/<to>/audio -w mywords.txt deck MyDeck  # or MyDeck.apkg
anki_deck -d /<path>/<to>/dict.xdxf -a /<path>/<to>/audio -w mywords.txt deck MyDeck -n "Deck name"

If you put dict and audio in a directory with structure:

dictdata/
  audio/
  dict.xdxf

then you may use:

anki_deck -i /<path>/<to>/dictdata -w mywords.txt ...

Also if words file is named words.txt you may skip -w:

anki_deck -i /<path>/<to>/dictdata ...

See help for all options:

anki_deck -h

Text flashcards

Text flashcards format:

<word> <translations> <transcription> <sound>

To import flashcards file create card with fields:

  • Front
  • Back
  • Transcription
  • Sound

Front Template:

{{Front}}
<br>
{{Transcription}}
<br>
{{Sound}}

Back Template:

{{FrontSide}}
<hr id=answer>
{{Back}}

Notes

Example of converting DSL to XDXF:

dictzip -d -k En-Ru-Apresyan.dsl.dz
makedict -i dsl -o xdxf En-Ru-Apresyan.dsl

Example of extracting sounds from .lsa:

lingvosound2resdb -l ~/.goldendict/content/Speech.lsa
rm -rf soundfiles
resdatabase2dir -i res.rifo -d audio
rm res.r* ; rm SoundE.ogg ; rm Speech.lsa

anki_deck's People

Contributors

skozlovf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ivan2kh mk386

anki_deck's Issues

Audio is not optional

Unless I doing something wrong, I believe that -a option is not actually optional. According to the read me audio should be optional.

Inside the anki_deck foler is a .xdxf and word.txt list.

The command I used is show below along with the corresponding error produced.

/usr/local/bin/python3.7 /Users/m/Programming/PythonProjects/anki_deck/anki_deck/cli.py -d dict.xdxf -w words.txt txt

Traceback (most recent call last):
  File "/Users/m/Programming/PythonProjects/anki_deck/anki_deck/cli.py", line 80, in <module>
    run()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/m/Programming/PythonProjects/anki_deck/anki_deck/cli.py", line 54, in txt
    get_cards(ctx['words'], ctx['dict'], ctx['audio'], handler)
  File "/Users/m/Programming/PythonProjects/anki_deck/anki_deck/parser.py", line 182, in get_cards
    need_audio = op.exists(sound_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/genericpath.py", line 19, in exists
    os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

This line seems to indicate that audio is required.

File "/Users/m/Programming/PythonProjects/anki_deck/anki_deck/parser.py", line 182, in get_cards
need_audio = op.exists(sound_path)

TypeError: sequence item 2: expected str instance, NoneType found

I have tried the script on a few dictionaries from https://sourceforge.net/projects/xdxf/

I run the script as anki-deck -d Documenten/English_French/dict.xdxf -w words-test.txt txt

I always get the following error:

Traceback (most recent call last):
  File "/home/jeroen/.local/bin//anki-deck", line 11, in <module>
    load_entry_point('anki-deck==0.0.1', 'console_scripts', 'anki-deck')()
  File "/usr/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/jeroen/.local/lib/python3.8/site-packages/anki_deck-0.0.1-py3.8.egg/anki_deck/cli.py", line 50, in txt
  File "/home/jeroen/.local/lib/python3.8/site-packages/anki_deck-0.0.1-py3.8.egg/anki_deck/parser.py", line 192, in get_cards
  File "/home/jeroen/.local/lib/python3.8/site-packages/anki_deck-0.0.1-py3.8.egg/anki_deck/flashcards.py", line 57, in handle
TypeError: sequence item 2: expected str instance, NoneType found

setup and usage issues

Hi I am runnning python 3.10
./setup.py just returns a flashing cursus and hangs till I ctrl-c.

But I can run without the install. However I get the following error as if it doesn't recognize the dict.xdxf file

ls dict.xdxf 
dict.xdxf
 bkelly  toolbox  ~  dev  anki_deck  master  1โœŽ  2+  $  python3 -m anki_deck.cli -d dict.xdxf deck file
ERROR: [Errno 2] No such file or directory: 'words.txt'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.