From 7791a4698643f8b48480b96a927ff08cf17363ca Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 14 Sep 2020 20:58:57 +0200 Subject: [PATCH] Add quizlet2anki --- quizlet2anki.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 quizlet2anki.py diff --git a/quizlet2anki.py b/quizlet2anki.py new file mode 100755 index 0000000..457955f --- /dev/null +++ b/quizlet2anki.py @@ -0,0 +1,24 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i python3 -p python3 +# I want to use Anki instead of Quizlet. However, Quizlet only provides a very +# limited “export” functionality, that exports something like csv, but does nut +# support quoting. So it will fail if your separation character is either your +# column or row separator (e.g. if you have multiple lines in one field). + +# This script takes unquoted data with uncommon separators (|||||| for columns, +# \n------\n for rows) and exports it as a more usable csv (quoted, cols +# separated by \t, rows separated by \n) +import sys + +outfile = sys.argv[1] + +quizlet_output = sys.stdin.read() + +maybe_tsv = ( + '"' + quizlet_output.replace("||||||", '"\t"').replace("\n------\n", '"\n"') + '"' +) + +maybe_tsv = maybe_tsv[:-2] + +with open(outfile, "w") as f: + f.write(maybe_tsv)