62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
# Copyright Sage Vaillancourt 2021
|
|
|
|
import os
|
|
import subprocess
|
|
from dataclasses import dataclass
|
|
|
|
from flask import send_from_directory
|
|
|
|
|
|
# latex /home/sage/Documents/latex/coverLetter/temp.tex'
|
|
# dvipdf /home/sage/Documents/latex/coverLetter/temp.dvi ~/Documents/SageVaillancourt_CoverLetter.pdf'
|
|
# rm -r /home/sage/Documents/latex/coverLetter/temp*'
|
|
|
|
@dataclass
|
|
class CLData():
|
|
username: str
|
|
company: str
|
|
jobandpronoun: str
|
|
skilltypes: str
|
|
myskills: str
|
|
closingtext: str
|
|
body: str
|
|
|
|
def get_pairs(self):
|
|
return [
|
|
("username", self.username),
|
|
("company", self.company),
|
|
("jobandpronoun", self.jobandpronoun),
|
|
("skilltypes", self.skilltypes),
|
|
("myskills", self.myskills),
|
|
("closingtext", self.closingtext),
|
|
("body", self.body),
|
|
]
|
|
|
|
def define(file, name, data, whitespace=""): file.write("\\def \\" + name + "{" + data + whitespace + "}\n")
|
|
|
|
def generate(data: CLData, unique):
|
|
proj_dir = os.path.dirname(os.getcwd()) + '/undercover/'
|
|
temp_dir = proj_dir + '/temp/'
|
|
unique_file = temp_dir + unique + ".tex"
|
|
f = open(unique_file, "w")
|
|
define(f, "username", data.username)
|
|
define(f, "thecompany", data.company)
|
|
define(f, "jobandpronoun", data.jobandpronoun, " ")
|
|
define(f, "skilltypes", data.skilltypes, " ")
|
|
define(f, "myskills", data.myskills, " ")
|
|
define(f, "closingtext", data.closingtext)
|
|
define(f, "body", data.body)
|
|
f.write(open(proj_dir + "/writing_templates/base.tex", "r").read())
|
|
f.close()
|
|
|
|
base_tex = temp_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
|
|
subprocess.run(['bash', '-c', com])
|
|
|
|
root_dir = os.path.dirname(os.getcwd())
|
|
download = root_dir + '/undercover/outputs/'
|
|
|
|
return send_from_directory(download, unique + ".pdf", as_attachment=True)
|