Skip to content

klei22/anki-from-csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anki from CSV

Anki is a vetted foss flashcards tool with spaced-repetition; however, using the Anki gui to create cards can take a long, long time.

Use this convenient anki_from_csv.py script to create your own flashcards straight from a csv file in a jiffy : )

Installation

To install have python3 and run:

./install_deps.sh

This repo depends on genanki.

Quickstart

  1. Create flashcards from numbers.csv by running: python3 anki_from_csv.py numbers

  2. Open the created numbers.apkg file iwth Anki.

Workflow

Using the anki_from_csv.py script is very simple two step process, see steps below:

Step 1/2: Create vocabulary csv with the vocab, e.g. mandarin_numbers.csv

With vim/emacs or preferred editor create a csv file.

See example below, mandarin_numbers.csv:

1,一,yī
2,二,èr
3,三,sān
4,四,sì
5,五,wǔ
6,六,liù
7,七,qī
8,八,bā
9,九,jiǔ
10,十,shí

Step 2/2: run anki_from_csv.py specifying vocab set

Run the following replacing <vocab_set_basename> with your vocab list:

python3 anki_from_csv.py <vocab_set_basename>

For example

python3 anki_from_csv.py mandarin_numbers

Make sure to omit the extension .csv

This last example will create a mandarin_numbers.apkg which you can open with any Anki app : )

Modifications

There are just two sections you'll need to modify if you'd like to add more fields or reduce to just two.

We'll show below an example for moving from English to Mandarin to just English to say French.

Create English to French Vocab CSV

create french_numbers.csv

1,un
2,deux
3,Trois
4,quatre
5,cinq
6,six
7,Sept
8,huit
9,neuf
10,Dix

edit the fields of the model

before:

    my_model = genanki.Model(
	    1000000000,
	    deck_name,
	    fields=[
		{'name': 'English'},
		{'name': 'Pinyin'},
		{'name': 'Simplified'},
		],
	    templates=[
		{
		    'name': 'Card Template 1',
		    'qfmt': '<center style="font-size:30px">{{English}}</center>',
		    'afmt': '{{FrontSide}} <hr> <p align=center style="font-size:30px"> {{Simplified}} <br /> {{Pinyin}}</p>',
		    },
		])

after:

    my_model = genanki.Model(
	    1000000000,
	    deck_name,
	    fields=[
		{'name': 'English'},
		{'name': 'French'},
		],
	    templates=[
		{
		    'name': 'Card Template 1',
		    'qfmt': '<center style="font-size:30px">{{English}}</center>',
		    'afmt': '{{FrontSide}} <hr> <p align=center style="font-size:30px"> {{French}}</p>',
		    },
		])

modify the number of rows that anki_from_csv.py reads

before

    # english, pinyin, simplified
    with open(csv_name, newline='') as csvfile:
        anki_reader = csv.reader(csvfile)
        for row in anki_reader:
            new_card = genanki.Note( 
                    model = my_model,
                    fields = [row[0],row[1],row[2]])
            my_deck.add_note(new_card)
    my_package = genanki.Package(my_deck)
    my_package.write_to_file(package_name)

after

    # english, pinyin, simplified
    with open(csv_name, newline='') as csvfile:
        anki_reader = csv.reader(csvfile)
        for row in anki_reader:
            new_card = genanki.Note( 
                    model = my_model,
                    fields = [row[0],row[1]])
            my_deck.add_note(new_card)
    my_package = genanki.Package(my_deck)
    my_package.write_to_file(package_name)

run the anki_from_csv.py script

python3 anki_from_csv.py french_numbers

and you should now have apkg called french_numbers.apkg ready to import to Anki from and Anki app : )

About

Quickly create Anki Flashcards Directly from CSV

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published