-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertificate_generator.py
58 lines (43 loc) · 2.03 KB
/
certificate_generator.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
from PIL import Image, ImageDraw, ImageFont
import pandas as pd
import yagmail
from config import pass_gmail ############################# ---- CONFIGURE SUA SENHA ------------
class EditCertificate:
'''classe que cria certificado dinamicamente e envia por email'''
def __init__(self):
self.read_data()
self.send_email_with_certificate()
def read_data(self):
self.df = pd.read_excel('lista_alunos.xlsx')
def send_email_with_certificate(self):
for _, row in self.df.iterrows():
name = row['Nome']
email = row['Email']
# Gerar um certificado com o nome
certificate_image = self.create_certificate(name)
# Enviar email personalizado
self.send_email_generic(name, email, certificate_image)
def create_certificate(self, name):
# Abrir a imagem de modelo
imagem = Image.open('template.png')
draw = ImageDraw.Draw(imagem)
font = ImageFont.truetype('calibrib.ttf', 150)
# Definindo a cor da fonte como preto (0, 0, 0)
draw.text((625, 950), name, font=font, fill=(0, 0, 0))
certificate_image = f'{name}_Certificate_Evangelizando_SQL.png'
imagem.save(certificate_image)
return certificate_image
def send_email_generic(self, name, email, certificate_image):
# Inicializar o Yagmail SMTP
usuario = yagmail.SMTP(user='seu_email@gmail.com', password=pass_gmail) ############################# ---- ALTERE POR SEU EMAIL ------------
assunto = 'Certificado de Participação - Evangelizando o SQL'
conteudo = f'Olá {name},\n\nAqui está o seu certificado de participação. \n\nAtenciosamente,\nAdministração Evangelizando SQL'
# Anexar a imagem do certificado
usuario.send(
to=email,
subject=assunto,
contents=conteudo,
attachments=certificate_image
)
print(f'Email enviado para {email} com sucesso!')
start = EditCertificate()