rh-id / a-flash-deck

A simple Flash Card application to assist in learning and remembering something.
GNU General Public License v3.0
29 stars 9 forks source link

any way to import anki decks? #17

Open justpeanuts opened 1 year ago

justpeanuts commented 1 year ago

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

rh-id commented 1 year ago

Hi, no there is no way

yuwash commented 11 months ago

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.