2021-07-11 10:47:36 +02:00
|
|
|
|
#!/usr/bin/env cached-nix-shell
|
2020-09-14 20:58:57 +02:00
|
|
|
|
#!nix-shell -i python3 -p python3
|
|
|
|
|
# I want to use Anki instead of Quizlet. However, Quizlet only provides a very
|
2021-03-15 19:13:21 +01:00
|
|
|
|
# limited “export” functionality, that exports something like csv, but does not
|
2020-09-14 20:58:57 +02:00
|
|
|
|
# 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).
|
|
|
|
|
|
2021-03-15 19:13:21 +01:00
|
|
|
|
# This script takes unquoted data with separators that don’t exist on the cards
|
|
|
|
|
# (世 for columns, 界 for rows) and exports it as a more usable csv (quoted,
|
|
|
|
|
# cols separated by tab, rows separated by newline).
|
2020-09-14 20:58:57 +02:00
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
outfile = sys.argv[1]
|
|
|
|
|
|
|
|
|
|
quizlet_output = sys.stdin.read()
|
|
|
|
|
|
2021-03-15 19:13:21 +01:00
|
|
|
|
maybe_tsv = '"' + quizlet_output.replace("世", '"\t"').replace("界", '"\n"')
|
2020-09-14 20:58:57 +02:00
|
|
|
|
|
|
|
|
|
maybe_tsv = maybe_tsv[:-2]
|
|
|
|
|
|
|
|
|
|
with open(outfile, "w") as f:
|
|
|
|
|
f.write(maybe_tsv)
|