-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_and_send.py
65 lines (54 loc) · 1.92 KB
/
generate_and_send.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
import os
from getpass import getpass
from time import sleep
import pandas as pd
import typer
from certifigen.email import EmailSender
from certifigen.generator import generate_certificate
COLUMNS_EXPECT = ["name", "mail", "work", "plenary_speaker"]
def main(path_csv: str):
# Read the table containing the participants
df = pd.read_csv(path_csv)
# Check that the columns are as expected
list_missing = list(set(COLUMNS_EXPECT) - set(df.columns))
if len(list_missing) > 0:
raise ValueError(f"The following columns are missing: {list_missing}")
# Create the "certificates" folder
if not os.path.exists("certificates"):
os.mkdir("certificates")
# Ask for email and passwordd
sender = input("Email sender: ")
password = getpass("Password: ")
# Login
try:
email = EmailSender(sender, password)
except:
print("Could not connect to email. Generating certificates anyway.")
# Generate the certificates for each participant
for idx, row in df.iterrows():
# Relevant participant information
name = row["name"].upper()
mail = row["mail"]
try:
user = mail.split("@")[0]
except AttributeError:
print(f"[ERROR] No email for {name}")
user = name.replace(" ", "-")
# Get the work title
work = row["work"]
# Certificate of poster presentation or talk
if len(work) > 0:
is_plenary_speaker = row["plenary_speaker"]
# Certificate of assistance
else:
work = None
is_plenary_speaker = False
generate_certificate(
name, user, work=work, is_plenary_speaker=is_plenary_speaker
)
# Send the email with the attached pdf
email.send_email_pdf(f"certificates/{user}.pdf", mail)
# Wait a second between each email
sleep(1)
if __name__ == "__main__":
typer.run(main)