Output file named after `username` input.
Clean up temp files after 30 minutes
This commit is contained in:
parent
759b5e0636
commit
4f27f8a174
20
latty.py
20
latty.py
|
@ -35,9 +35,10 @@ class CLData():
|
||||||
def define(file, name, data, whitespace=""): file.write("\\def \\" + name + "{" + data + whitespace + "}\n")
|
def define(file, name, data, whitespace=""): file.write("\\def \\" + name + "{" + data + whitespace + "}\n")
|
||||||
|
|
||||||
def generate(data: CLData, unique):
|
def generate(data: CLData, unique):
|
||||||
|
import threading
|
||||||
proj_dir = os.path.dirname(os.getcwd()) + '/undercover/'
|
proj_dir = os.path.dirname(os.getcwd()) + '/undercover/'
|
||||||
temp_dir = proj_dir + '/temp/'
|
output_dir = proj_dir + 'outputs/'
|
||||||
unique_file = temp_dir + unique + ".tex"
|
unique_file = output_dir + unique + ".tex"
|
||||||
f = open(unique_file, "w")
|
f = open(unique_file, "w")
|
||||||
define(f, "username", data.username)
|
define(f, "username", data.username)
|
||||||
define(f, "thecompany", data.company)
|
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.write(open(proj_dir + "/writing_templates/base.tex", "r").read())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
base_tex = temp_dir + unique + ".tex"
|
base_tex = output_dir + unique + ".tex"
|
||||||
com = "pdflatex -halt-on-error -jobname=outputs/" + unique + " " + base_tex
|
com = "pdflatex -halt-on-error -jobname=outputs/" + unique + " " + base_tex
|
||||||
print("COM: '" + com + "'")
|
print("COM: '" + com + "'")
|
||||||
#TODO: If error, don't try to return the pdf
|
#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())
|
root_dir = os.path.dirname(os.getcwd())
|
||||||
download = root_dir + '/undercover/outputs/'
|
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 + ".*"])
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class CLForm(Form):
|
||||||
|
|
||||||
def get_unique():
|
def get_unique():
|
||||||
import uuid
|
import uuid
|
||||||
unique = str(uuid.uuid1().hex)[0:8]
|
unique = str(uuid.uuid1().hex)
|
||||||
print("Unique ID: " + unique)
|
print("Unique ID: " + unique)
|
||||||
return unique
|
return unique
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue