From 8a15cc524f27f7f149f5ad4f7586c32377523afc Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 23 Jul 2021 17:30:15 -0400 Subject: [PATCH] Init commit TODO: Collect form data, process data into latex renderables, generate unique id when submitting, styling, etc. --- .gitignore | 19 ++++++++ flaskr/__init__.py | 44 +++++++++++++++++ flaskr/templates/_formhelpers.html | 12 +++++ flaskr/templates/writing.html | 23 +++++++++ latty.py | 29 ++++++++++++ writing.py | 76 ++++++++++++++++++++++++++++++ writing_templates/base.tex | 34 +++++++++++++ writing_templates/default.tex | 48 +++++++++++++++++++ 8 files changed, 285 insertions(+) create mode 100644 .gitignore create mode 100644 flaskr/__init__.py create mode 100644 flaskr/templates/_formhelpers.html create mode 100644 flaskr/templates/writing.html create mode 100644 latty.py create mode 100644 writing.py create mode 100644 writing_templates/base.tex create mode 100644 writing_templates/default.tex diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf42a90 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +venv/ + +*.pyc +__pycache__/ + +*.aux +*.log +*.pdf + +instance/ +outputs + +.pytest_cache/ +.coverage +htmlcov/ + +dist/ +build/ +*.egg-info/ diff --git a/flaskr/__init__.py b/flaskr/__init__.py new file mode 100644 index 0000000..e6b250d --- /dev/null +++ b/flaskr/__init__.py @@ -0,0 +1,44 @@ +# Copyright Sage Vaillancourt 2021 + +import os + +from flask import ( + Flask, redirect, url_for, render_template, send_from_directory +) + +import subprocess +import time + +from writing import writing_blueprint +from latty import generate + +def create_app(test_config=None): + app = Flask(__name__, instance_relative_config=True) + app.config.from_mapping( + SECRET_KEY='dev', + DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), + ) + + if test_config is None: + app.config.from_pyfile('config.py', silent=True) + else: + app.config.from_mapping(test_config) + + try: + os.makedirs(app.instance_path) + except OSError: + pass + + @app.route('/outputs/') + def output(unique): + root_dir = os.path.dirname(os.getcwd()) + download = root_dir + '/undercover/outputs/' + generate(unique) + return send_from_directory(download, unique + ".pdf", as_attachment=True) + + app.register_blueprint( + writing_blueprint, + #url_prefix='/writing', + ) + + return app diff --git a/flaskr/templates/_formhelpers.html b/flaskr/templates/_formhelpers.html new file mode 100644 index 0000000..0b6bfda --- /dev/null +++ b/flaskr/templates/_formhelpers.html @@ -0,0 +1,12 @@ +{% macro render_field(field) %} +
{{ field.label }} +
{{ field(**kwargs)|safe }} + {% if field.errors %} +
    + {% for error in field.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+{% endmacro %} diff --git a/flaskr/templates/writing.html b/flaskr/templates/writing.html new file mode 100644 index 0000000..ed55b2a --- /dev/null +++ b/flaskr/templates/writing.html @@ -0,0 +1,23 @@ + + + + + +

UnderCover: The secret cover letter generator

+ +{% from "_formhelpers.html" import render_field %} +
+
+ {{ render_field(form.username) }} + {{ render_field(form.company) }} + {{ render_field(form.jobandpronoun) }} + {{ render_field(form.skilltypes) }} + {{ render_field(form.myskills) }} + {{ render_field(form.body) }} + {{ render_field(form.closingtext) }} +
+

+
+ + + diff --git a/latty.py b/latty.py new file mode 100644 index 0000000..95f0e01 --- /dev/null +++ b/latty.py @@ -0,0 +1,29 @@ +# Copyright Sage Vaillancourt 2021 + +import os +import subprocess +from dataclasses import dataClass + + +# 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(): + username: str + company: str + jobandpronoun: str + skilltypes: str + myskills: str + closingtext: str + body: str + +def generate(unique): + template_dir = os.path.dirname(os.getcwd()) + '/undercover/writing_templates' + base_tex = template_dir + '/base.tex' + com = "pdflatex -jobname=outputs/" + unique + " " + base_tex + subprocess.run(['bash', '-c', com]) + return base_tex diff --git a/writing.py b/writing.py new file mode 100644 index 0000000..127f034 --- /dev/null +++ b/writing.py @@ -0,0 +1,76 @@ +# Copyright Sage Vaillancourt 2021 + +from flask import (Blueprint, render_template, request) +from wtforms import Form, BooleanField, StringField, TextAreaField, validators + + +writing_blueprint = Blueprint('writing', __name__,) + +default_defines = [ + ("username", "Sage"), + ("company", "BananaCorp"), + ("jobandpronoun", "Banana Stocker"), + ("skilltypes", "practical"), + ("myskills", "stocking"), + ("closingtext", "I am looking forward to hearing from you"), + ("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."""), +] + +class CLForm(Form): + username = StringField('Username', + [validators.Length(min=4, max=99)], + default="Sage Bongos" + ) + company = StringField('Company', + [validators.Length(min=4, max=99)], + default="BananaCorp" + ) + jobandpronoun = StringField('Job and Pronoun', + [validators.Length(min=4, max=99)], + default="Banana Stocker" + ) + skilltypes = StringField('Skill Type', + [validators.Length(min=4, max=99)], + default="practical" + ) + myskills = StringField('My Skills', + [validators.Length(min=4, max=99)], + default="stocking" + ) + closingtext = StringField('Closing Text', + [validators.Length(min=4, max=99)], + default="I am looking forward to hearing from you" + ) + body = TextAreaField('Body', + [validators.Length(min=4, max=9999)], + default=""" + 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.""" + ) + +@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 + + for define in default_defines: + print("\\def \\" + define[0] + " {xxx}") + return render_template('writing.html', + form=form, + unique="abcdef", + defines=default_defines + ) diff --git a/writing_templates/base.tex b/writing_templates/base.tex new file mode 100644 index 0000000..7772e78 --- /dev/null +++ b/writing_templates/base.tex @@ -0,0 +1,34 @@ + +\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. + +} + +\documentclass[12pt]{letter} +\signature{\username} + +\longindentation=0pt +\begin{document} +\begin{letter}{} + +\opening{Dear \thecompany,} + +\body + +\closing{\closingtext,} + +\end{letter} +\end{document} diff --git a/writing_templates/default.tex b/writing_templates/default.tex new file mode 100644 index 0000000..00cdea2 --- /dev/null +++ b/writing_templates/default.tex @@ -0,0 +1,48 @@ + +\def \thecompany {BananCorp} +\def \jobandpronoun {PusherBoy } +\def \skilltypes {broad, practical } +\def \myskills {software design principles} +% CoverLetter.tex - Create a cover letter using an included vars.tex + +% \def \username {Sage Vaillancourt} +% \def \thecompany {Travelers} +% \def \jobandpronoun {a Software Engineer } +% \def \skilltypes {broad, practical } +% \def \myskills {computer systems} + +\include{vars} + +\documentclass[12pt]{letter} +\signature{Sage Vaillancourt} + +\longindentation=0pt +\begin{document} +\begin{letter}{} + +\opening{Dear \thecompany,} + +My name is Sage Vaillancourt. I'm excited for the opportunity to work as +\jobandpronoun with your company. It's clear that you're looking for a hard worker who +has a \skilltypes knowledge of \myskills, so I'm certain that I'd be a +perfect fit to work with you. + +I am someone who has been passionate about computers my whole life, and I have +spent a substantial amount of my own time working to make them better. I've +endeavored to learn about programming, hardware, and networking, as well as +running Linux on my own machines, and helping others with theirs. With this +knowledge, I’m more than capable of solving my own problems on the job, and I +pride myself on an ability to work quickly and calmly through difficult +situations. I hope I can further utilize these skills with your company. + +After looking over my resume, I hope that you will find me to be the type +of person you're looking for. I would be happy to elaborate on any of my +information or provide some references if it would be useful to you. I can be +contacted by phone at (850) 405-7164 or via email at sagev9000@tutanota.com. + +Thank you for your consideration. + +\closing{I look forward to hearing from you,} + +\end{letter} +\end{document}