Created
May 8, 2025 05:59
-
-
Save olliecheng/a7fe279f42054433fbd021c70ad21f96 to your computer and use it in GitHub Desktop.
Anki: Basic to Cloze card type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
if len(sys.argv) != 3: | |
print("Usage: python script.py input.tsv output.tsv") | |
sys.exit(1) | |
input_path = sys.argv[1] | |
output_path = sys.argv[2] | |
with open(input_path, 'r', encoding='utf-8') as infile, open(output_path, 'w', encoding='utf-8', newline='') as outfile: | |
reader = csv.reader(infile, delimiter='\t') | |
writer = csv.writer(outfile, delimiter='\t') | |
for row in reader: | |
if row and row[0].startswith('#'): | |
writer.writerow(row) # keep metadata | |
else: | |
if len(row) >= 5: | |
prompt = row[3] | |
answer = row[4] | |
row[3] = f"{prompt}<br /><br />{{{{c1::{answer}}}}}" | |
row[4] = "" | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See link at https://oycheng.notion.site/anki-basic-to-cloze