mail
Laurent 1 year ago
parent 0438fd1af6
commit 3c7acb967c
  1. 12
      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}")

Loading…
Cancel
Save