Skip to content

Convert an orgmode-formatted file into a format suitable for importing as Anki cards.

License

Notifications You must be signed in to change notification settings

eindiran/orgmode-to-anki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

orgmode-to-anki

Convert a .org file into a format suitable for importing into Anki as a deck. The file is tab-separated, using partial HTML formatting to specify newlines and complex textual elements.

Instructions

Run the orgmode_to_anki.py script over a .org file to produce a partially HTML formatted file suitable for use with Anki.

If your .org file is called foo.org, run the following command:

./orgmode_to_anki.py -i foo.org -o foo.txt

If you are on a non-POSIX operating system (e.g. Windows), run the command as:

python3  orgmode_to_anki.py -i foo.org -o foo.txt

This will produce a new file called foo.txt. You can then import the file into Anki using the standard import flow. Make sure that the field separating character is set to tab and that the "Allow HTML in fields" option is checked.

Existing decks vs. new decks

The Anki interface allows you to either update an existing deck or to create a new deck during the import process. If you have previously created a deck and just want to add new cards, choose the update existing deck option. Otherwise, you will need to create a new deck and point to it while importing the text file generated by orgmode-to-anki. You can do this by clicking the button adjacent to the word "Deck", then selecting "Add" to create a new deck, then choosing that deck.

Flags

To find out more information about the available arguments, run:

./orgmode_to_anki.py -h

If you are on a non-POSIX operating system (e.g. Windows), run the command as:

python3  orgmode_to_anki.py -h

In addition to -h or --help, there are a number of other flags:

  • -i or --input specifies the .org file to use as a source. Required.
  • -o or --output specifies the location where the output file should be saved. A file type will not be added automatically if this option is specified. By default, the output file is the basename of the input file + .txt. Optional.
  • -a or --append sets that the output file should not be overwritten, but instead should be appended to. Given that Anki ignores duplicated cards by default, it shouldn't often be necessary to do this. Optional.

Encoding

This script only works with UTF-8 (or ASCII) encoded text. If you have a .org file that is encoded in another encoding, the script will complain and fail to complete running. Please convert it to UTF-8 using a tool like iconv.

For example, if you have a latin-1 encoded file:

iconv -f iso-8859-1 -t utf-8 foo.org -o foo_utf8.org

Using the script with cron

If the .org file you are converting to an Anki deck will be updated often, it might make sense to automate running the orgmode-to-anki script. A simple way to do that is to create a cron job that runs the script periodically.

Start by editing your crontab by running the command crontab -e. This will open your user's crontab file in a text editor. You can then add a new line which specifies when to run the script. An example:

0 19 * * * /usr/local/sbin/orgmode_to_anki.py -i ~/foo.org -o ~/Anki-Decks/foo.txt

This command supposes that you have orgmode_to_anki.py in your /usr/local/sbin directory, your input file foo.org in your home directory, and you want to put your output file into a directory called Anki-Decks inside your home directory. It will run each day at 7 PM. If you need help specifying the correct schedule for your job, you can use this site, which is an easy-to-use crontab schedule editing tool.

Then, everytime you open Anki, quickly run through the update existing deck import flow, using the file that the cron job has been updating as input.

About

Convert an orgmode-formatted file into a format suitable for importing as Anki cards.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages