a-flash-deck icon indicating copy to clipboard operation
a-flash-deck copied to clipboard

any way to import anki decks?

Open justpeanuts opened this issue 2 years ago • 2 comments

Hi! Is there any way to import flashcard decks from the flashcard app anki?

justpeanuts avatar Aug 21 '23 02:08 justpeanuts

Hi, no there is no way

rh-id avatar Aug 21 '23 04:08 rh-id

I don’t know about Anki but some apps (notably quizlet, cram.com) allow exporting cards as csv/tsv. For the simplest (text-only) flashcards, you can create a file that can be imported by the app using the following little function (which you can easily amend for other input formats):

    with open(csv_file) as f:
        lines = f.readlines()
    deck_uid = -812177  # Doesn’t matter much
    cards = []
    for line in lines:
        question, answer = line.split("\t")
        cards.append(
            {
                "id": 1,
                "deckId": 1,
                "ordinal": 0,
                "question": question,
                "questionImage": "",
                "questionVoice": "",
                "answer": answer,
                "answerImage": "",
            }
        )

    print(
        json.dumps(
            [
                {
                    "serialVersionUID": deck_uid,
                    "deck": {
                        "id": 1,
                        "name": deck_name,
                        "createdDateTime": "1703530960604",
                        "updatedDateTime": "1703530960604",
                    },
                    "cardList": cards,
                }
            ]
        )
    )

Write the output of the script into a file called Decks.json and then make a zip archive containing only that file.

I’m rather new to this app but just made this work by looking at an export file that the app produces.

yuwash avatar Dec 26 '23 09:12 yuwash