From 4e6e3a33ae787848236d8b64a1649c393c334a78 Mon Sep 17 00:00:00 2001 From: Elias Xu <124101026+Elias2660@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:56:35 -0400 Subject: [PATCH] make final tweaks --- Main/Main.py | 19 ++++++++++----- Main/SendEmail.py | 27 ++++++++++++++-------- Main/__pycache__/SendEmail.cpython-39.pyc | Bin 3073 -> 3022 bytes 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Main/Main.py b/Main/Main.py index 1ec9585..856ae8d 100644 --- a/Main/Main.py +++ b/Main/Main.py @@ -1,18 +1,23 @@ # %% import pandas as pd -import numpy as np from SendEmail import send_email +import time data = pd.read_csv('../data/actualfinaljpromlist.csv', names = ["date", "sessionid", "ip", "name", "number1", "1staddress", "place", "state", "number2", "number3", "paid", "blank","blank2", "approval", "email", "name2", "email2", "osis", "homeroom", "purchase"]) # %% -start = 0 -end = 100 +start = 100 +end = 220 +# %% + +highest = data.shape[0] + +# %% -for i in range(start, end): +for i in range(start, min(end, highest)): p = data.iloc[i] name = (str(p["name2"]).strip().split(" ")[0]).strip() name = name[0].upper() + name[1:] @@ -20,8 +25,10 @@ session_id = p["sessionid"].strip() approval = p["approval"] if ("Approved" in approval) : - send_email([email, "yinwei.zhang@stuysu.org", "exu51@stuy.edu", "ethan.sie@stuysu.org"], session_id, name) - + print(send_email([email, "yinwei.zhang@stuysu.org", "exu51@stuy.edu", "ethan.sie@stuysu.org"], session_id, name)) + time.sleep(3) + else: + print(f"{name} is not approved") diff --git a/Main/SendEmail.py b/Main/SendEmail.py index 4a54d6f..e167543 100644 --- a/Main/SendEmail.py +++ b/Main/SendEmail.py @@ -17,9 +17,9 @@ def send_email(recipients: list, session: str, name: str) -> str: if not SMTPserver or not sender or not USERNAME or not PASSWORD: sys.exit("Missing environment variables") - print(f"SMTP Server: {SMTPserver}") - print(f"Sender: {sender}") - print(f"Username: {USERNAME}") + # print(f"SMTP Server: {SMTPserver}") + # print(f"Sender: {sender}") + # print(f"Username: {USERNAME}") content = f""" @@ -44,7 +44,7 @@ def send_email(recipients: list, session: str, name: str) -> str: """ - subject = "Your Jprom Ticket" + subject = "Your Junior Prom 2024 Ticket" try: msg = EmailMessage() @@ -58,22 +58,29 @@ def send_email(recipients: list, session: str, name: str) -> str: msg.set_content(content, subtype="html") CreateBarcode.createBarcode(session, "barcode_image.png") - attachFile.attach_file(msg, "barcode_image.png") + + try: + attachFile.attach_file(msg, "barcode_image.png") + except Exception as e: + print(f"Failed to attach file to {name}: {str(e)}") + return + + conn = SMTP(SMTPserver) - conn.set_debuglevel(True) # Enable debugging output + # conn.set_debuglevel(True) # Enable debugging output conn.login(USERNAME, PASSWORD) try: conn.sendmail(sender, recipients, msg.as_string()) finally: conn.quit() - return "Mail sent successfully" + return f"Mail sent successfully to {name}" except Exception as e: print("Mail failed:", str(e)) - sys.exit(f"Mail failed; {str(e)}") + return + # sys.exit(f"Mail failed; {str(e)}") if __name__ == "__main__": - # print(send_email(["esie50@stuy.edu"], 2083480230980, "Ethan")) + print(send_email(["exu51@stuy.edu"], 2083480230980, "Ethan")) # print(send_email(["yzhang50@stuy.edu"], 2083480230980, "Will")) - print() \ No newline at end of file diff --git a/Main/__pycache__/SendEmail.cpython-39.pyc b/Main/__pycache__/SendEmail.cpython-39.pyc index 41a395bdec4f24f90d7c61d33d8204a4ffb154c4..8792c6242c9a3e40e4208c8cdae6201e168a4768 100644 GIT binary patch delta 726 zcmY+C&rcIU6vt;~x7+>EZcC{xKN_+U4-zkhU}6Y(Fk;k%NCL4z63eDDg_U-f>`o1B zrV=d&FPM@&0!e%HOuTsWAMoOB{{~N-P4snz7-tUeedm4Od!NI+pZH!h?Q~j4aDH5F z*QNBSS;8Mr@4cQenMsv%nI@@vEWgUIEYiDhqK8yxNdL_=vb0p7-k2qRa&$;yZp z1$hihNCk$*G`KCUVM+iq@fV{9^#2h42NxK@w*m*(;j@q$R%Wt_QhBPnPHk<1RA@P+oWq^%y-*a3GuH%c7%j?1CW{Yc(e z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