Now generates customized PDFs

This commit is contained in:
Sage Vaillancourt 2021-07-23 23:09:08 -04:00
parent 8a15cc524f
commit aaa4117e7f
5 changed files with 66 additions and 29 deletions

4
.gitignore vendored
View File

@ -8,7 +8,9 @@ __pycache__/
*.pdf *.pdf
instance/ instance/
outputs
outputs/
temp/
.pytest_cache/ .pytest_cache/
.coverage .coverage

View File

@ -9,7 +9,7 @@ from flask import (
import subprocess import subprocess
import time import time
from writing import writing_blueprint import writing
from latty import generate from latty import generate
def create_app(test_config=None): def create_app(test_config=None):
@ -37,7 +37,7 @@ def create_app(test_config=None):
return send_from_directory(download, unique + ".pdf", as_attachment=True) return send_from_directory(download, unique + ".pdf", as_attachment=True)
app.register_blueprint( app.register_blueprint(
writing_blueprint, writing.writing_blueprint,
#url_prefix='/writing', #url_prefix='/writing',
) )

View File

@ -2,14 +2,14 @@
import os import os
import subprocess import subprocess
from dataclasses import dataClass from dataclasses import dataclass
from flask import send_from_directory
# latex /home/sage/Documents/latex/coverLetter/temp.tex' # latex /home/sage/Documents/latex/coverLetter/temp.tex'
# dvipdf /home/sage/Documents/latex/coverLetter/temp.dvi ~/Documents/SageVaillancourt_CoverLetter.pdf' # dvipdf /home/sage/Documents/latex/coverLetter/temp.dvi ~/Documents/SageVaillancourt_CoverLetter.pdf'
# rm -r /home/sage/Documents/latex/coverLetter/temp*' # rm -r /home/sage/Documents/latex/coverLetter/temp*'
# cp "$HOME/Documents/SageVaillancourt_CoverLetter.pdf" "$HOME/Documents/CoverLetters/.pdf"'
# qpdfview $HOME/Documents/SageVaillancourt_CoverLetter.pdf'
@dataclass @dataclass
class CLData(): class CLData():
@ -21,9 +21,30 @@ class CLData():
closingtext: str closingtext: str
body: str body: str
def generate(unique): def define(file, name, data, whitespace=""):
template_dir = os.path.dirname(os.getcwd()) + '/undercover/writing_templates' file.write("\\def \\" + name + "{" + data + whitespace + "}\n")
base_tex = template_dir + '/base.tex'
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 com = "pdflatex -jobname=outputs/" + unique + " " + base_tex
print("COM: '" + com + "'")
subprocess.run(['bash', '-c', com]) subprocess.run(['bash', '-c', com])
return base_tex
root_dir = os.path.dirname(os.getcwd())
download = root_dir + '/undercover/outputs/'
return send_from_directory(download, unique + ".pdf", as_attachment=True)

View File

@ -3,6 +3,8 @@
from flask import (Blueprint, render_template, request) from flask import (Blueprint, render_template, request)
from wtforms import Form, BooleanField, StringField, TextAreaField, validators from wtforms import Form, BooleanField, StringField, TextAreaField, validators
from latty import (CLData, generate)
writing_blueprint = Blueprint('writing', __name__,) writing_blueprint = Blueprint('writing', __name__,)
@ -60,17 +62,29 @@ class CLForm(Form):
Thank you for your consideration.""" Thank you for your consideration."""
) )
def get_unique():
return "get_unique"
@writing_blueprint.route('/', methods=('GET', 'POST')) @writing_blueprint.route('/', methods=('GET', 'POST'))
def index(): def index():
form = CLForm(request.form) form = CLForm(request.form)
if request.method == 'POST' and form.validate(): if request.method == 'POST' and form.validate():
username = form.username.data data = CLData(
return 'Thank ' + username username=form.username.data,
company=form.company.data,
jobandpronoun=form.jobandpronoun.data,
skilltypes=form.skilltypes.data,
myskills=form.myskills.data,
closingtext=form.closingtext.data,
body=form.body.data,
)
return generate(data, get_unique())
#return send_from_directory(download, unique + ".pdf", as_attachment=True)
for define in default_defines: for define in default_defines:
print("\\def \\" + define[0] + " {xxx}") print("\\def \\" + define[0] + " {xxx}")
return render_template('writing.html', return render_template('writing.html',
form=form, form=form,
unique="abcdef", unique=get_unique(),
defines=default_defines defines=default_defines
) )

View File

@ -1,21 +1,21 @@
\def \username {Sage Vaillancourt} %\def \username {Sage Vaillancourt}
\def \thecompany {BananCorp} %\def \thecompany {BananCorp}
\def \jobandpronoun {PusherBoy } %\def \jobandpronoun {PusherBoy }
\def \skilltypes {broad, practical } %\def \skilltypes {broad, practical }
\def \myskills {software design principles } %\def \myskills {software design principles }
\def \closingtext {I am looking forward to hearing from you} %\def \closingtext {I am looking forward to hearing from you}
\def \body { %\def \body {
My name is \username. I would like to work as \jobandpronoun with your % My name is \username. I would like to work as \jobandpronoun with your
company. I think my knowledge of \myskills will contribute well to your % company. I think my knowledge of \myskills will contribute well to your
team. % team.
%
I am passionate about my work, and think we would work well together. % I am passionate about my work, and think we would work well together.
%
Thank you for your consideration. % Thank you for your consideration.
%
} %}
\documentclass[12pt]{letter} \documentclass[12pt]{letter}
\signature{\username} \signature{\username}