Now generates customized PDFs
This commit is contained in:
parent
8a15cc524f
commit
aaa4117e7f
|
@ -8,7 +8,9 @@ __pycache__/
|
|||
*.pdf
|
||||
|
||||
instance/
|
||||
outputs
|
||||
|
||||
outputs/
|
||||
temp/
|
||||
|
||||
.pytest_cache/
|
||||
.coverage
|
||||
|
|
|
@ -9,7 +9,7 @@ from flask import (
|
|||
import subprocess
|
||||
import time
|
||||
|
||||
from writing import writing_blueprint
|
||||
import writing
|
||||
from latty import generate
|
||||
|
||||
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)
|
||||
|
||||
app.register_blueprint(
|
||||
writing_blueprint,
|
||||
writing.writing_blueprint,
|
||||
#url_prefix='/writing',
|
||||
)
|
||||
|
||||
|
|
35
latty.py
35
latty.py
|
@ -2,14 +2,14 @@
|
|||
|
||||
import os
|
||||
import subprocess
|
||||
from dataclasses import dataClass
|
||||
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*'
|
||||
# cp "$HOME/Documents/SageVaillancourt_CoverLetter.pdf" "$HOME/Documents/CoverLetters/.pdf"'
|
||||
# qpdfview $HOME/Documents/SageVaillancourt_CoverLetter.pdf'
|
||||
|
||||
@dataclass
|
||||
class CLData():
|
||||
|
@ -21,9 +21,30 @@ class CLData():
|
|||
closingtext: str
|
||||
body: str
|
||||
|
||||
def generate(unique):
|
||||
template_dir = os.path.dirname(os.getcwd()) + '/undercover/writing_templates'
|
||||
base_tex = template_dir + '/base.tex'
|
||||
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/'
|
||||
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
|
||||
print("COM: '" + 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)
|
||||
|
|
20
writing.py
20
writing.py
|
@ -3,6 +3,8 @@
|
|||
from flask import (Blueprint, render_template, request)
|
||||
from wtforms import Form, BooleanField, StringField, TextAreaField, validators
|
||||
|
||||
from latty import (CLData, generate)
|
||||
|
||||
|
||||
writing_blueprint = Blueprint('writing', __name__,)
|
||||
|
||||
|
@ -60,17 +62,29 @@ class CLForm(Form):
|
|||
Thank you for your consideration."""
|
||||
)
|
||||
|
||||
def get_unique():
|
||||
return "get_unique"
|
||||
|
||||
@writing_blueprint.route('/', methods=('GET', 'POST'))
|
||||
def index():
|
||||
form = CLForm(request.form)
|
||||
if request.method == 'POST' and form.validate():
|
||||
username = form.username.data
|
||||
return 'Thank ' + username
|
||||
data = CLData(
|
||||
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:
|
||||
print("\\def \\" + define[0] + " {xxx}")
|
||||
return render_template('writing.html',
|
||||
form=form,
|
||||
unique="abcdef",
|
||||
unique=get_unique(),
|
||||
defines=default_defines
|
||||
)
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
|
||||
\def \username {Sage Vaillancourt}
|
||||
\def \thecompany {BananCorp}
|
||||
\def \jobandpronoun {PusherBoy }
|
||||
\def \skilltypes {broad, practical }
|
||||
\def \myskills {software design principles }
|
||||
\def \closingtext {I am looking forward to hearing from you}
|
||||
%\def \username {Sage Vaillancourt}
|
||||
%\def \thecompany {BananCorp}
|
||||
%\def \jobandpronoun {PusherBoy }
|
||||
%\def \skilltypes {broad, practical }
|
||||
%\def \myskills {software design principles }
|
||||
%\def \closingtext {I am looking forward to hearing from you}
|
||||
|
||||
\def \body {
|
||||
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
|
||||
team.
|
||||
|
||||
I am passionate about my work, and think we would work well together.
|
||||
|
||||
Thank you for your consideration.
|
||||
|
||||
}
|
||||
%\def \body {
|
||||
% 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
|
||||
% team.
|
||||
%
|
||||
% I am passionate about my work, and think we would work well together.
|
||||
%
|
||||
% Thank you for your consideration.
|
||||
%
|
||||
%}
|
||||
|
||||
\documentclass[12pt]{letter}
|
||||
\signature{\username}
|
||||
|
|
Loading…
Reference in New Issue