Skip to content

Instantly share code, notes, and snippets.

@AdamHepner
Created March 17, 2015 20:01
Show Gist options
  • Save AdamHepner/8196fc079b0f5cd55d6a to your computer and use it in GitHub Desktop.
Save AdamHepner/8196fc079b0f5cd55d6a to your computer and use it in GitHub Desktop.
Ankify - convert text file containing {{placeholders}} (one card per line), into csv with {{c1::cloze placeholders}} that the Anki can import relatively safely
from __future__ import with_statement
import re
import sys
import random
if __name__=="__main__":
ctr = 1
print sys.argv[1]
outfile = sys.argv[1]+".csv"
with open(sys.argv[1],'r') as the_input:
with open(outfile,'w') as the_output:
for line in the_input.readlines():
if re.match(r'^\s*$',line) is None:
m = r'{{(?!c\d)'
s = line
for i in range(len(re.findall(m,s))):
#while re.match(m,s):
s = re.sub(m,"{{c"+str(i+1)+"::",s,1)
i += 1
print s
if re.match(r'{{c\d+::.+?(::.+?)}}',s):
the_output.write(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment