2021-07-23 17:30:15 -04:00
|
|
|
# Copyright Sage Vaillancourt 2021
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
2021-07-23 23:09:08 -04:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
from flask import send_from_directory
|
2021-07-23 17:30:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2021-07-24 00:26:44 -04:00
|
|
|
def get_pairs():
|
|
|
|
return [
|
|
|
|
("username", username),
|
|
|
|
("company", company),
|
|
|
|
("jobandpronoun", jobandpronoun),
|
|
|
|
("skilltypes", skilltypes),
|
|
|
|
("myskills", myskills),
|
|
|
|
("closingtext", closingtext),
|
|
|
|
("body", body),
|
|
|
|
]
|
|
|
|
|
|
|
|
def define(file, name, data, whitespace=""): file.write("\\def \\" + name + "{" + data + whitespace + "}\n")
|
2021-07-23 23:09:08 -04:00
|
|
|
|
|
|
|
def generate(data: CLData, unique):
|
|
|
|
proj_dir = os.path.dirname(os.getcwd()) + '/undercover/'
|
|
|
|
template_dir = os.path.dirname(os.getcwd()) + '/undercover/temp/'
|
|
|
|
unique_file = template_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 = template_dir + unique + ".tex"
|
2021-07-23 17:30:15 -04:00
|
|
|
com = "pdflatex -jobname=outputs/" + unique + " " + base_tex
|
2021-07-23 23:09:08 -04:00
|
|
|
print("COM: '" + com + "'")
|
2021-07-23 17:30:15 -04:00
|
|
|
subprocess.run(['bash', '-c', com])
|
2021-07-23 23:09:08 -04:00
|
|
|
|
|
|
|
root_dir = os.path.dirname(os.getcwd())
|
|
|
|
download = root_dir + '/undercover/outputs/'
|
|
|
|
|
|
|
|
return send_from_directory(download, unique + ".pdf", as_attachment=True)
|