Wait until after generating markdown before opening output file.

This commit is contained in:
Daniel Valentine 2022-11-17 21:41:53 -07:00
parent 3bcf104307
commit 14c95045ba

View File

@ -97,19 +97,6 @@ WARNING: This script will overwrite the output file if it exists.
sys.stderr.write("\t" + e.__str__() + "\n")
return 1
if parsed_args.OUTPUT_FILE == "-":
out = sys.stdout
else:
try:
mode="x"
if os.path.exists(parsed_args.OUTPUT_FILE):
mode="w"
out = open(parsed_args.OUTPUT_FILE, mode)
except Exception as e:
sys.stderr.write("Error opening '{}' for writing:\n".format(parsed_args.OUTPUT_FILE))
sys.stderr.write("\t" + e.__str__() + "\n")
return 1
table_preamble = "|URL|Network|Version|Location|Behind Cloudflare?|Comment|\n|-|-|-|-|-|-|\n"
table_rows = []
for instance in instances["instances"]:
@ -166,6 +153,16 @@ WARNING: This script will overwrite the output file if it exists.
description
))
if parsed_args.OUTPUT_FILE == "-":
out = sys.stdout
else:
try:
out = open(parsed_args.OUTPUT_FILE, "w" if os.path.exists(parsed_args.OUTPUT_FILE) else "x")
except Exception as e:
sys.stderr.write("Error opening '{}' for writing:\n".format(parsed_args.OUTPUT_FILE))
sys.stderr.write("\t" + e.__str__() + "\n")
return 1
out.write(table_preamble)
for row in table_rows:
out.write(row)