This commit is contained in:
2025-05-12 11:40:52 -03:00
parent e42abd328c
commit 3c94b5ad46
9 changed files with 1306 additions and 0 deletions

33
certs/hello.py Normal file
View File

@@ -0,0 +1,33 @@
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')