Output file named after `username` input.

Clean up temp files after 30 minutes
This commit is contained in:
Sage Vaillancourt 2021-07-24 15:25:58 -04:00
parent 759b5e0636
commit 4f27f8a174
2 changed files with 17 additions and 5 deletions

View File

@ -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 + ".*"])

View File

@ -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