""" This module is used for creating an org-drill file from a
text file containing lines with
Chinese characters\tpinyin\tenglish\n.
Example input file :
这个 zhège This
那些 nàxiē Those
几本 jǐ běn Several/How many items (e.g. books)
我不是学生。 Wǒ bú shì xuésheng.I am not a student.
Run python make_chinese_org_drill_file.py -h for help on
how to use the script and the command-line options.
By default hide1_firstmore cards are created.
To make twosided cards pass the option -c twosided.
"""
import argparse
parser = argparse.ArgumentParser(
description = 'Convert text file to org drill file for learning Chinese')
parser.add_argument('input_file',
help="text file with chinese, pinyin and english")
parser.add_argument('output_file',
help="name of output file which should with .org extension")
parser.add_argument('-c', '--card_type', choices=['twosided','hide1_firstmore'],
default='hide1_firstmore', help="Set DRILL_CARD_TYPE property")
parser.add_argument('-f', '--first_level_heading',
help="Top level org heading, e.g. HSK2 Sentences")
parser.add_argument('-s', '--second_level_heading', choices=['word', 'sentence'],
help="Flash card for words or sentences?")
args = parser.parse_args()
of = open(args.output_file, "w", encoding='utf-8')
of.write("# -*- mode: org; coding: utf-8 -*-\n")
of.write("#+STARTUP: showall\n\n")
of.write(f"* {args.first_level_heading}\n")
with open(args.input_file, encoding='utf-8') as f:
for line in f:
of.write(f"** {args.second_level_heading.capitalize()}\t\t\t:drill:\n")
of.write(f"\t:PROPERTIES:\n\t:DRILL_CARD_TYPE: {args.card_type}\n")
of.write('\t:END:\n\n')
ch, py, en = line.rstrip().split('\t')
if args.card_type == 'hide1_firstmore':
of.write(f"Cn: [{ch}]\n")
of.write(f"En: [{en}]\n\n")
of.write('*** Pinyin\n')
of.write(f"{py}\n\n")
else:
of.write('Translate this sentence.\n\n')
of.write('*** Chinese\n')
of.write(f"{ch}\n")
of.write('*** English\n')
of.write(f"{en}\n")
of.write('*** Pinyin\n')
of.write(f"{py}\n\n")
of.close()