UnderCover/latty.py

61 lines
1.9 KiB
Python
Raw Normal View History

# 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
# 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():
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"
com = "pdflatex -jobname=outputs/" + unique + " " + base_tex
2021-07-23 23:09:08 -04:00
print("COM: '" + com + "'")
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)