Skip to content

Instantly share code, notes, and snippets.

@7h3730B
Created September 1, 2021 15:59
Show Gist options
  • Save 7h3730B/8d8bc5b6fa85a97c69becb863cecd034 to your computer and use it in GitHub Desktop.
Save 7h3730B/8d8bc5b6fa85a97c69becb863cecd034 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import os
import argparse
import re
parser = argparse.ArgumentParser()
parser.add_argument("--file", "-f", type=str, required=True)
parser.add_argument("--output", "-o", type=str, required=True)
def main(file, output):
print(f"Parsing {file}")
if os.path.exists(output):
print(f"deleting {output}")
os.remove(output)
inputfile, outputfile = open(file), open(output, 'w')
for line in inputfile:
if line.startswith('" ANKI') != True:
continue
description = re.sub('"( )?ANKI(I)?(:)?( )?', "", line).strip()
next_line = next(inputfile)
if next_line.startswith('" '):
continue
outputfile.write(f"{description}; {next_line}")
if __name__ == "__main__":
args = parser.parse_args()
main(args.file, args.output)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment