def main():
<EOL>def _draw_and_save(title, subtitle, author, filename):<EOL><INDENT>"""<STR_LIT>"""<EOL>cover_image = draw(title, subtitle, author)<EOL>if filename == "<STR_LIT:->":<EOL><INDENT>assert not "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>_, ext = os.path.splitext(os.path.basename(filename))<EOL>if ext.upper() == "<STR_LIT>":<EOL><INDENT>try:<EOL><INDENT>with open(filename, "<STR_LIT:wb>") as f:<EOL><INDENT>cover_image.save(f)<EOL><DEDENT><DEDENT>except FileNotFoundError:<EOL><INDENT>print("<STR_LIT>" + filename)<EOL>return <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>print("<STR_LIT>" + ext + "<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT><DEDENT>return <NUM_LIT:0><EOL><DEDENT>usage = "<STR_LIT>"<EOL>parser = argparse.ArgumentParser(usage=usage)<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT:title>", help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>", help="<STR_LIT>", default="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>", help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>", help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>", help="<STR_LIT>")<EOL>args = parser.parse_args()<EOL>if args.json_covers:<EOL><INDENT>try:<EOL><INDENT>with open(args.json_covers, "<STR_LIT:r>") as f:<EOL><INDENT>for line in f:<EOL><INDENT>data = json.loads(line)<EOL>print("<STR_LIT>" + data["<STR_LIT>"])<EOL>status = _draw_and_save(<EOL>data["<STR_LIT:title>"],<EOL>data["<STR_LIT>"],<EOL>data["<STR_LIT>"],<EOL>data["<STR_LIT:filename>"]<EOL>)<EOL>if status:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>return <NUM_LIT:0><EOL><DEDENT>except ValueError:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>print("<STR_LIT>" + args.json_covers)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not args.title or not args.author:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>elif not args.outfile:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>return _draw_and_save(args.title, args.subtitle, args.author, args.outfile)<EOL><DEDENT><DEDENT>return <NUM_LIT:1><EOL>
The main() function handles command line arguments and maneuvers the cover
image generation.