diff --git a/latty.py b/latty.py index ee28c8e..c159c30 100644 --- a/latty.py +++ b/latty.py @@ -35,9 +35,10 @@ class CLData(): def define(file, name, data, whitespace=""): file.write("\\def \\" + name + "{" + data + whitespace + "}\n") def generate(data: CLData, unique): + import threading proj_dir = os.path.dirname(os.getcwd()) + '/undercover/' - temp_dir = proj_dir + '/temp/' - unique_file = temp_dir + unique + ".tex" + output_dir = proj_dir + 'outputs/' + unique_file = output_dir + unique + ".tex" f = open(unique_file, "w") define(f, "username", data.username) define(f, "thecompany", data.company) @@ -49,7 +50,7 @@ def generate(data: CLData, unique): f.write(open(proj_dir + "/writing_templates/base.tex", "r").read()) f.close() - base_tex = temp_dir + unique + ".tex" + base_tex = output_dir + unique + ".tex" com = "pdflatex -halt-on-error -jobname=outputs/" + unique + " " + base_tex print("COM: '" + com + "'") #TODO: If error, don't try to return the pdf @@ -58,4 +59,15 @@ def generate(data: CLData, unique): root_dir = os.path.dirname(os.getcwd()) download = root_dir + '/undercover/outputs/' - return send_from_directory(download, unique + ".pdf", as_attachment=True) + threading.Timer(60 * 30, cleanup, [output_dir + unique]).start() + return send_from_directory( + download, + unique + ".pdf", + attachment_filename=data.username.replace(" ", "") + "_CoverLetter.pdf", + as_attachment=True + ) + +def cleanup(unique): + print(unique) + subprocess.run(['bash', '-c', "rm " + unique + ".*"]) + diff --git a/writing.py b/writing.py index 8cb169f..038d103 100644 --- a/writing.py +++ b/writing.py @@ -48,7 +48,7 @@ class CLForm(Form): def get_unique(): import uuid - unique = str(uuid.uuid1().hex)[0:8] + unique = str(uuid.uuid1().hex) print("Unique ID: " + unique) return unique