Send Email formatted Python

Asked

Viewed 37 times

-1

Good afternoon, I’m in need of some help regarding python and pandas.

I need to generate a weekly ranking from some reports I extract from the system, the data I’m able to query but I need me to pick up all these display that I print in the terminal and put them formatted a table next to each other with the ranking position of each and send in the body of the email with automatic trigger.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pandas.core.indexes.base import Index
import win32com.client as win32

arquivo1 = 'TA0413-CPC.EV-Listagemgeraldeatividadedoconsultor.xlsx'
arquivo2 = 'RAA-RelatoriodeAnalisedeAgendas.xlsx'
arquivo3 = 'Validacoesdedespesas.xlsx'


ranking1= pd.read_excel(arquivo1,sheet_name='Sheet')
ranking2= pd.read_excel(arquivo2,sheet_name='Sheet')
#display (ranking1)

#Atendimentos
atendimentos =ranking1.sort_values(['Qtd. Atendimentos'],ascending=False)
display("Ranking Atendimentos",atendimentos[["Consultor","Qtd. Atendimentos"]])


#Clientes atendidos
clientes = ranking1.sort_values(['Qtd. Cliente Atendidos'],ascending=False)
display("Ranking Clientes Atendidos",clientes[["Consultor","Qtd. Cliente Atendidos"]])


#Agendas planejadas
agendap = ranking1.sort_values(['Agendas Planejadas'],ascending=False)
display("Ranking Agendas Planejadas",agendap[["Consultor","Agendas Planejadas"]])

#Agendas Realizadas
agendar= ranking1.sort_values(['Agendas Realizadas'],ascending=False)
display("Ranking Agendas realizadas",agendar[["Consultor","Agendas Realizadas"]])

# % completude de agenda

ranking1['Porcentagem']=(ranking1['Agendas Realizadas']/ranking1['Agendas Planejadas'])*100
porcentagemf=ranking1.sort_values(['Porcentagem'],ascending=False)
display(porcentagemf[["Consultor","Porcentagem"]])
 
 #Quantidade de serviços
servicos= ranking1.sort_values(['Qtd. Serviços'],ascending=False)
display(servicos[["Consultor","Qtd. Serviços"]])


#Rtr Gerados
rtr = ranking2.groupby(["Usuário"]).sum("RTR Gerado")
display (rtr.sort_values(by=["RTR Gerado"],ascending=False)[["RTR Gerado"]])




# Integração com o Outlook
outlook = win32.Dispatch('outlook.application')
# Email
email = outlook.CreateItem(0)
# Info Emails
email.To = ""
email.Subject = "Teste disparo de email"
email.HTMLBody = f""" 
<p>Olá Lucas, esse é o</p> 
<p>teste do email automatico em phyton.</p> 
<p>Deu certo.</p> 

<p>Ass:</p>
"""
email.Display()
email.Send()
print("Email Enviado")

1 answer

0

Pandas has the method .to_html() to convert each table into HTML and you add to the report.

You’ve tested this method?

  • I didn’t know this method, I’ll take a look here. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.