Skip to content

Instantly share code, notes, and snippets.

@brendanmckenzie
Created August 10, 2014 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanmckenzie/77b1097a49774d3d5edb to your computer and use it in GitHub Desktop.
Save brendanmckenzie/77b1097a49774d3d5edb to your computer and use it in GitHub Desktop.
from os import unlink
from uuid import uuid3, NAMESPACE_DNS
from task_queue.app import app
from utils import upload, pdf, html
from model import Session, AgencyPdf
def upload_pdf(pdf_file):
file_name = str(uuid3(NAMESPACE_DNS, 'takeoffgo.com')) + '.pdf'
path = 'pdf/' + file_name
return upload(pdf_file, path)
@app.task
def generate_pdf(id):
db = Session()
req = db.query(AgencyPdf).get(id)
html_file = html.from_template(req.agencytemplate.content, req.data)
pdf_file = pdf.from_html(html_file)
url = upload_pdf(pdf_file)
unlink(html_file)
unlink(pdf_file)
req.url = url
db.commit()
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment