34 lines
843 B
Python
34 lines
843 B
Python
import locale
|
|
from datetime import date
|
|
from uuid import uuid4
|
|
|
|
from jinja2 import Template
|
|
from weasyprint import HTML
|
|
|
|
locale.setlocale(locale.LC_TIME, 'pt_BR')
|
|
today = date.today()
|
|
|
|
with open('cert.html', encoding='utf-8') as f:
|
|
html = f.read()
|
|
|
|
|
|
def cpf_fmt(s: str) -> str:
|
|
"""Returns a string as a Brazilian CPF number."""
|
|
return '{}.{}.{}-{}'.format(s[:3], s[3:6], s[6:9], s[9:])
|
|
|
|
|
|
template = Template(html)
|
|
html_rendered = template.render(
|
|
id=uuid4(),
|
|
name='Sérgio Rafael de Siqueira',
|
|
cpf=cpf_fmt('07879819908'),
|
|
progress=91.99,
|
|
course='NR-10 Complementar (SEP)',
|
|
today=today.strftime('%-d de %B de %Y'),
|
|
start_date=today.strftime('%d/%m/%Y'),
|
|
finish_date=today.strftime('%d/%m/%Y'),
|
|
due_date=today.strftime('%d/%m/%Y'),
|
|
)
|
|
|
|
HTML(string=html_rendered, base_url='').write_pdf('cert.pdf')
|