-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
101 lines (67 loc) · 3.11 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer
from config import ISSUER, SESSIONS
from custom_types import Issuer, Sessions, Session
from write_number import monetario
def generate_for_all_dates(
issuer: Issuer = ISSUER, sessions: Sessions = SESSIONS
) -> dict:
all_texts: dict = {}
for date in sessions["dates"]:
session: Session = {}
session["name"] = sessions["name"]
session["cost"] = sessions["cost"]
session["cpf"] = sessions["cpf"]
session["written_cost"] = monetario(session["cost"])
session["date"] = date
all_texts[date] = compose_texts(issuer=issuer, session=session)
return all_texts
def compose_texts(issuer: Issuer, session: Session) -> dict:
texts = {
"title_text": "<para align=center>RECIBO</para>",
"summary_text": f"<para align=left>Valor total: R${str(session['cost'])},00 ({session['written_cost']})</para>",
"main_text": f"<para align=left>Recebi de {session['name']}, CPF {session['cpf']}, a importância de R${str(session['cost'])},00 ({session['written_cost']}) referente a uma sessão de psicoterapia, realizada no dia {session['date']}, online via videoconferência.</para>",
"issuer_text": f"<para align=center> Emitente: {issuer['name']} <br /> CPF: {issuer['cpf']} Telefone: {issuer['telephone']} <br /> Endereço: {issuer['address']} <br /></para>",
"psychologist_text": f"<para align=center>{issuer['name']} <br /> Psicóloga <br /> CRP {issuer['crp']}</para>",
}
return texts
def format_paragraphs(texts: dict) -> list:
styles = getSampleStyleSheet()
flowables = []
title = Paragraph(texts["title_text"], style=styles["Heading1"])
flowables.append(title)
spacer = Spacer(width=0, height=30)
flowables.append(spacer)
p = Paragraph(texts["summary_text"], style=styles["Normal"])
flowables.append(p)
spacer = Spacer(width=0, height=30)
flowables.append(spacer)
p = Paragraph(texts["main_text"], style=styles["Normal"])
flowables.append(p)
spacer = Spacer(width=0, height=30)
flowables.append(spacer)
p = Paragraph(texts["issuer_text"], style=styles["Normal"])
flowables.append(p)
spacer = Spacer(width=0, height=50)
flowables.append(spacer)
p = Paragraph(texts["psychologist_text"], style=styles["Normal"])
flowables.append(p)
return flowables
def build_doc(name: str, flowables: list) -> None:
doc = SimpleDocTemplate(f"docs/{name}.pdf", pagesize=A4)
doc.build(flowables)
def format_doc_name(date: str) -> str:
date_parts = date.split("/")
doc_name = "recibo-{}-{}-{}".format(date_parts[2], date_parts[1], date_parts[0])
return doc_name
def build_all_docs() -> None:
all_texts = generate_for_all_dates()
for date in all_texts:
flowables = format_paragraphs(texts=all_texts[date])
doc_name = format_doc_name(date=date)
build_doc(name=doc_name, flowables=flowables)
def main() -> None:
build_all_docs()
if __name__ == "__main__":
main()