From 3c7acb967c8a10eab28922a95cea288c7687ec38 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 21 Oct 2024 17:36:44 +0200 Subject: [PATCH] add logs --- tournaments/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tournaments/views.py b/tournaments/views.py index 367b32c..a1d0019 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -438,7 +438,7 @@ def simple_form_view(request): def send_email_to_jap_list(): # Open the CSV file - with open('tournaments/static/misc/jap-test.csv', 'r') as file: + with open('tournaments/static/misc/jap-liste2.csv', 'r') as file: csv_reader = csv.reader(file) def log_error(message): @@ -446,6 +446,11 @@ def send_email_to_jap_list(): timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') log_file.write(f"{timestamp}: {message}\n") + def log_progress(batch): + with open('email_progress.log', 'a') as log_file: + timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + log_file.write(f"{batch}: \n") + batch = [] for row in csv_reader: if len(row) >= 4: @@ -453,7 +458,7 @@ def send_email_to_jap_list(): mail = row[3] batch.append((mail, name)) - if len(batch) == 10: + if len(batch) == 5: for email, recipient_name in batch: try: send_email(email, recipient_name) @@ -464,7 +469,8 @@ def send_email_to_jap_list(): print(error_message) batch = [] - time.sleep(2) + log_progress(batch) + time.sleep(3) else: print(f"Row doesn't have enough elements: {row}")