minor Updates
This commit is contained in:
parent
541b947609
commit
2f3f1d9a13
22
src/main.py
22
src/main.py
@ -1,5 +1,5 @@
|
|||||||
from env import CSV_FILE_PATH, DRAW_PER_PERSON, EMAIL_SUBJECT, EMAIL_BODY
|
from env import DRAW_PER_PERSON, HISTORY_YEARS, EMAIL_SUBJECT, EMAIL_BODY
|
||||||
from file_io import open_csv, save_csv
|
from file_io import load_history, save_csv, load_participants
|
||||||
from draw import draw_names
|
from draw import draw_names
|
||||||
from emailer import send_email
|
from emailer import send_email
|
||||||
from utils import get_current_time
|
from utils import get_current_time
|
||||||
@ -11,29 +11,29 @@ def send_all_emails(new_draw):
|
|||||||
for participant in new_draw:
|
for participant in new_draw:
|
||||||
name = participant[0]
|
name = participant[0]
|
||||||
receiver_email = participant[1]
|
receiver_email = participant[1]
|
||||||
draws = ", ".join(participant[2:]) # List of recipients
|
draws = ", ".join(participant[2:])
|
||||||
message = EMAIL_BODY.format(name=name, draws=draws)
|
message = EMAIL_BODY.format(name=name, draws=draws)
|
||||||
subject = EMAIL_SUBJECT.format(year=current_year)
|
subject = EMAIL_SUBJECT.format(year=current_year)
|
||||||
send_email(receiver_email, subject, message) # Send the email
|
send_email(receiver_email, subject, message)
|
||||||
print(f"Email sent to {name} ({receiver_email})")
|
print(f"Email sent to {name} ({receiver_email})")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
# Load previous draw data
|
# Load data from historical CSVs and this year's participants
|
||||||
old_draw = open_csv(CSV_FILE_PATH)
|
history_data = load_history(HISTORY_YEARS)
|
||||||
|
|
||||||
# Perform new draw
|
current_year = date.today().year
|
||||||
new_draw = draw_names(old_draw, DRAW_PER_PERSON)
|
current_participants = load_participants() # Load participants data
|
||||||
|
|
||||||
|
# Perform the draw
|
||||||
|
new_draw = draw_names(current_participants, history_data, DRAW_PER_PERSON)
|
||||||
# Send emails to participants
|
# Send emails to participants
|
||||||
send_all_emails(new_draw)
|
send_all_emails(new_draw)
|
||||||
|
|
||||||
# Save new draw results
|
# Save new draw results
|
||||||
save_csv(new_draw, CSV_FILE_PATH)
|
save_csv(new_draw, current_year)
|
||||||
|
|
||||||
# Output completion time
|
|
||||||
print(f"Process completed at {get_current_time()[1]} on {get_current_time()[0]}")
|
print(f"Process completed at {get_current_time()[1]} on {get_current_time()[0]}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error occurred: {e}")
|
print(f"Error occurred: {e}")
|
||||||
# Retry or handle errors
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user