Spaces:
Sleeping
Sleeping
Update app.py
Browse files6 unmodified lines789101112435 unmodified lines4484494504514524534544554564574584594606 unmodified linesfrom reportlab.lib.pagesizes import A4from reportlab.lib.utils import ImageReaderfrom reportlab.pdfgen import canvasload_dotenv()api_token = os.environ.get("SYNAP")435 unmodified linesprint("erro:", e)print("Tentando novamente")def limpar(self, texto):texto = texto.replace("<img>", "<img>")texto = texto.replace("<p>", "<p>").replace("</p>", "</p>")texto = texto.replace("<div>", "<div>").replace("</div>", "</div>")texto = texto.replace("<h1>", "<h1>").replace("</h1>", "</h1>")return textodef save(self):self.c.save()6 unmodified lines789101112131415435 unmodified lines4514524534544554564574584594604614624634644654664674684694704714724734744754764776 unmodified linesfrom reportlab.lib.pagesizes import A4from reportlab.lib.utils import ImageReaderfrom reportlab.pdfgen import canvasimport refrom html import escapeload_dotenv()api_token = os.environ.get("SYNAP")435 unmodified linesprint("erro:", e)print("Tentando novamente")def limpar(self, texto: str) -> str:if not texto:return ""# Escapa qualquer coisa perigosa primeirotexto = escape(texto)# Reverte apenas as tags PERMITIDAS pelo ReportLabtexto = texto.replace("<br/>", "<br/>")texto = texto.replace("<br>", "<br/>")texto = texto.replace("<strong>", "<strong>")texto = texto.replace("</strong>", "</strong>")# Normaliza <br>texto = re.sub(r"<br\s*/?>", "<br/>", texto, flags=re.IGNORECASE)# Remove excesso de quebrastexto = re.sub(r"(?:<br/>){3,}", "<br/><br/>", texto)return texto.strip()def save(self):self.c.save()
app.py+23-6