# Takes in a single argument, which is a plaintext file to convert to # HTML for display on the website. import os import sys def add_header_tags(input): return "\n

" + input + "

\n\n" def add_p_tags(input): return "

" + input + "

\n\n" print("Starting the Article Maker") if ".txt" in sys.argv[1]: input_file_name = sys.argv[1] else: sys.exit("No good input file found") input_lines = [] with open(input_file_name, "r") as input_file: input_lines = [line for line in input_file.readlines() if len(line.strip()) > 0] print(str(input_lines)) filename, ext = os.path.splitext(input_file_name) output_file_name = filename + ".html" content_as_html = [] header = add_header_tags(input_lines.pop(0).strip()) content_as_html.append(header) for line in input_lines: content_as_html.append(add_p_tags(line.strip())) print(str(content_as_html)) template_contents = [] with open("./blog/robot_blog_template.html", "r") as templatefile: template_contents = templatefile.readlines() replacementindex = template_contents.index("

$$INSERT_CONTENTS$$

\n") beginning, ending = template_contents[:replacementindex], template_contents[replacementindex+1:] final_output = [] for line in beginning: final_output.append(line) for line in content_as_html: final_output.append(line) for line in ending: final_output.append(line) with open(output_file_name, "w+") as output_file: for line in final_output: output_file.write(line)