This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path99-report.py
63 lines (52 loc) · 2.09 KB
/
99-report.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
'''
Gera uma relatório HTML dos resultados.
'''
import logging
#import pdfkit
import pandas as pd
from jinja2 import Environment, FileSystemLoader
from datetime import datetime
# Importa as configurações
exec(open('00-configuracoes.py').read())
with open(r'cache/data_base.txt', 'r') as f:
data_base = f.read()
logging.info('Carregando os resultados...')
teste_balver_msc = pd.read_excel(r'output/teste-contas-balver-msc.xlsx', sheet_name='dados').fillna('').to_dict('records')
teste_msc_balver = pd.read_excel(r'output/teste-contas-msc-balver.xlsx', sheet_name='dados').fillna('').to_dict('records')
teste_valores_balver_msc = pd.read_excel(r'output/teste-valores-balver-msc.xlsx', sheet_name='dados').fillna('').to_dict('records')
teste_msc_anterior_atual = pd.read_excel(r'output/teste-msc-anterior-atual.xlsx', sheet_name='dados').fillna('').to_dict('records')
logging.info('Criando o ambiente de template...')
env = Environment(
loader=FileSystemLoader('templates')
)
logging.info('Gerando o relatório...')
template = env.get_template('report.html')
template.globals['datetime'] = datetime
html = template.render(
data_base=data_base,
teste_balver_msc=teste_balver_msc,
teste_msc_balver=teste_msc_balver,
teste_valores_balver_msc=teste_valores_balver_msc,
teste_msc_anterior_atual=teste_msc_anterior_atual
)
logging.info('Salvando o relatório HTML...')
with open(r'output/report.html', 'w', encoding='utf-8') as f:
f.write(html)
import os
print(r'file:///'+os.path.join(os.getcwd(), r'output/report.html').replace('\\', '/'))
# logging.info('Salvando o relatório PDF...')
# pdf_options = {
# 'grayscale': True,
# 'margin-bottom': '0.5in',
# 'margin-left': '1in',
# 'margin-right': '0.5in',
# 'margin-top': '1in',
# 'orientation': 'Portrait',
# 'title': 'Conferência da MSC de {}'.format(data_base),
# 'encoding': 'UTF-8',
# 'page-offset': 1,
# 'page-size': 'A4',
# 'enable-local-file-access': None
# }
# pdfkit.from_file(r'output/report.html', r'output/report.pdf', options=pdf_options)
logging.info('Geração dos relatórios concluída!')