-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_site.py
More file actions
371 lines (296 loc) · 9.56 KB
/
generate_site.py
File metadata and controls
371 lines (296 loc) · 9.56 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
import os
import json
import re
from collections import defaultdict
import shutil
TASKS_DIR = "tasks"
ISSUES_DIR = os.path.join(TASKS_DIR, "issues")
OUTPUT_DIR = "docs"
OUTPUT_FILE = os.path.join(OUTPUT_DIR, "index.html")
# ----------------------------------------
# Converter LaTeX simples para HTML
# ----------------------------------------
def latex_to_html(text):
if not text:
return ""
text = text.replace("\\bigskip", "<br><br>")
text = re.sub(r"\\textbf{([^}]*)}", r"<strong>\1</strong>", text)
text = re.sub(r"\\textit{([^}]*)}", r"<em>\1</em>", text)
text = text.replace("\\begin{itemize}", "<ul>")
text = text.replace("\\end{itemize}", "</ul>")
text = text.replace("\\item", "<li>")
text = re.sub(r"\\url{([^}]*)}", r'<a href="\1" target="_blank">\1</a>', text)
return text
# ----------------------------------------
# Ler tasks
# ----------------------------------------
def load_tasks():
tasks = []
for file in os.listdir(TASKS_DIR):
if file.endswith(".json"):
path = os.path.join(TASKS_DIR, file)
with open(path, encoding="utf-8") as f:
data = json.load(f)
data["codigo"] = file.replace(".json", "")
tasks.append(data)
return tasks
# ----------------------------------------
# Ler issues
# ----------------------------------------
def load_issues():
issues = []
if not os.path.exists(ISSUES_DIR):
return issues
for file in os.listdir(ISSUES_DIR):
if file.endswith(".json"):
path = os.path.join(ISSUES_DIR, file)
with open(path, encoding="utf-8") as f:
data = json.load(f)
data["codigo"] = file.replace(".json", "")
issues.append(data)
return issues
# ----------------------------------------
# Agrupar por prefixo
# ----------------------------------------
def group_by_prefix(tasks):
groups = defaultdict(list)
for task in tasks:
match = re.match(r"([a-zA-Z]+)", task["codigo"])
prefix = match.group(1) if match else "outros"
groups[prefix].append(task)
return groups
# ----------------------------------------
# Ordenar numericamente
# ----------------------------------------
def sort_tasks(tasks):
return sorted(
tasks,
key=lambda t: int(re.search(r"\d+", t["codigo"]).group())
)
# conta quantas issues abertas existem para um prefixo de tarefa
def count_open_issues(task_codigo, issues):
return len([
i for i in issues
if i["codigo"].startswith(task_codigo)
and i.get("status") is True
])
# ----------------------------------------
# Resumo por estagiário
# ----------------------------------------
def generate_estagiario_summary(tasks, issues):
from collections import defaultdict
estagiarios = defaultdict(list)
for task in tasks:
lista_est = task.get("estagiarios", [])
# Garantia extra caso venha string por erro antigo
if isinstance(lista_est, str):
lista_est = [lista_est]
for est in lista_est:
if not est or est == "Não Há":
continue
estagiarios[est].append(task)
# Ordenação alfabética normal
nomes = sorted(estagiarios.keys())
html = ''
for nome in nomes:
tarefas = estagiarios[nome]
total_peso = sum(t.get("peso", 0) for t in tarefas)
html += f"""
<h3 class="mt-4">{nome}</h3>
<table class="table table-bordered table-sm">
<thead>
<tr>
<th style="width:120px;">Código</th>
<th>Título</th>
<th style="width:80px;">Peso</th>
<th style="width:110px;">Pendências</th>
</tr>
</thead>
<tbody>
"""
total_pendencias = 0
for t in sorted(tarefas, key=lambda x: x["codigo"]):
pendencias = count_open_issues(t["codigo"], issues)
total_pendencias += pendencias
html += f"""
<tr>
<td><a href="#{t["codigo"]}">{t["codigo"]}</a></td>
<td>{t.get("titulo","")}</td>
<td>{t.get("peso","")}</td>
<td>{"<span class='badge bg-danger'>" + str(pendencias) + "</span>" if pendencias > 0 else pendencias}</td>
</tr>
"""
html += f"""
<tr class="table-secondary fw-bold">
<td colspan="2">Soma</td>
<td>{total_peso}</td>
<td>{total_pendencias}</td>
</tr>
</tbody>
</table>
"""
return html
# ----------------------------------------
# Resumo por responsável
# ----------------------------------------
def generate_responsavel_summary(tasks, issues):
responsaveis = defaultdict(list)
for task in tasks:
resp = task.get("responsavel", "Não definido")
responsaveis[resp].append(task)
# Ordenar deixando "Desativado" por último
nomes = sorted(responsaveis.keys(), key=lambda x: (x == "Desativado", x))
html = ''
for nome in nomes:
tarefas = responsaveis[nome]
total_peso = sum(t.get("peso", 0) for t in tarefas)
html += f"""
<h3 class="mt-4">{nome}</h3>
<table class="table table-bordered table-sm">
<thead>
<tr>
<th style="width:120px;">Código</th>
<th>Título</th>
<th style="width:80px;">Peso</th>
<th style="width:110px;">Pendências</th>
</tr>
</thead>
<tbody>
"""
total_pendencias = 0
for t in sorted(tarefas, key=lambda x: x["codigo"]):
pendencias = count_open_issues(t["codigo"], issues)
total_pendencias += pendencias
html += f"""
<tr>
<td><a href="#{t["codigo"]}">{t["codigo"]}</a></td>
<td>{t.get("titulo","")}</td>
<td>{t.get("peso","")}</td>
<td>{"<span class='badge bg-danger'>" + str(pendencias) + "</span>" if pendencias > 0 else pendencias}</td>
</tr>
"""
html += f"""
<tr class="table-secondary fw-bold">
<td colspan="2">Soma</td>
<td>{total_peso}</td>
<td>{total_pendencias}</td>
</tr>
</tbody>
</table>
"""
return html
# ----------------------------------------
# Gerar HTML
# ----------------------------------------
def generate_html(tasks, issues):
groups = group_by_prefix(tasks)
sorted_prefixes = sorted(groups.keys())
html = """
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>TI - FFLCH</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { padding: 40px; }
.card { margin-bottom: 20px; }
.prefix-title { margin-top: 80px; border-bottom: 2px solid #ddd; padding-bottom: 10px; }
.issue-item { font-size: 0.9rem; color: #555; margin-left:15px; }
.top-link { font-size: 0.85rem; }
.summary-box { background:#f8f9fa; padding:20px; border-radius:10px; margin-bottom:40px; }
</style>
</head>
<body>
<div class="container-fluid">
<a id="top"></a>
<h1 class="mb-4">TI - FFLCH</h1>
<div class="mb-4">
<a href="meetings.html" class="btn btn-primary">
Reuniões Técnicas
</a>
</div>
"""
# ------------------------------------------------
# PDF NO TOPO
# ------------------------------------------------
html += """
<div class="mb-5">
<img src="ti_fflch.jpg" class="img-fluid w-100" alt="TI FFLCH">
</div>
"""
html += generate_responsavel_summary(tasks, issues)
html += "<br><hr><h2><u>Estagiários(as)</u></h2>"
html += generate_estagiario_summary(tasks, issues)
# ------------------------------------------------
# SUMÁRIO POR PREFIXO
# ------------------------------------------------
html += '<div class="summary-box">'
html += '<h4>Sumário por Prefixo</h4>'
html += '<ul>'
for prefix in sorted_prefixes:
html += f'<li><a href="#{prefix}">{prefix.upper()}</a></li>'
html += '</ul></div>'
# ------------------------------------------------
# TASKS
# ------------------------------------------------
for prefix in sorted_prefixes:
html += f'<h2 class="prefix-title" id="{prefix}">{prefix.upper()} '
html += f'<a href="#top" class="top-link">(voltar ao topo)</a>'
html += '</h2>'
for task in sort_tasks(groups[prefix]):
related = [
i for i in issues
if i["codigo"].startswith(task["codigo"])
and i.get("status") is True
]
badge = f' <span class="badge bg-danger">{len(related)} pendência(s)</span>' if related else ""
html += f"""
<div class="card shadow-sm">
<div class="card-body">
<h5 id="{task["codigo"]}">{task["codigo"]} | {task["titulo"]} {badge}</h5>
<table class="table table-sm">
<tr><th style="width:120px;">Peso</th><td>{task.get("peso","")}</td></tr>
<tr><th>Responsável</th><td>{task.get("responsavel","")}</td></tr>
<tr><th>Estagiário(a)</th><td>{"; ".join(task.get("estagiarios", []))}</td></tr>
</table>
<div class="mt-3">
{latex_to_html(task.get("descricao",""))}
</div>
"""
if related:
html += "<hr><strong>Pendências:</strong>"
for issue in related:
html += f"""
<div class="issue-item">
<strong>{issue.get("codigo")}</strong><br>
{latex_to_html(issue.get("descricao",""))}
</div>
"""
html += "</div></div>"
html += """
</div>
</body>
</html>
"""
return html
def copy_files():
files = ["meetings.html"]
for file in files:
source_path = file
destination_path = os.path.join(OUTPUT_DIR, os.path.basename(file))
shutil.copy(file, destination_path)
# ----------------------------------------
# MAIN
# ----------------------------------------
def main():
os.makedirs(OUTPUT_DIR, exist_ok=True)
tasks = load_tasks()
issues = load_issues()
html = generate_html(tasks, issues)
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
f.write(html)
copy_files()
print("Site gerado em:", OUTPUT_FILE)
if __name__ == "__main__":
main()