Skip to content

Commit

Permalink
fix flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Simran Mattu committed Oct 10, 2024
1 parent 6fd749b commit 7bb2bcd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
31 changes: 23 additions & 8 deletions woudc_data_registry/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,37 @@ def send_feedback(ctx, failed_files, test, ops):
message = message.replace(
"$EMAIL_SUMMARY", "\n".join(contributor[1:]))
specific_subject = subject.replace('contributor_acronym', acronym)

if test:
to_email_addresses = config.WDR_EMAIL_TO.split(",")
subject = (
'TEST: WOUDC data processing report ({})'.format(acronym))
LOGGER.info('Sending Test data report to agency: {} with emails to: {}'.format(acronym, to_email_addresses))
send_email(message, subject, from_email_address, to_email_addresses,
host, port, cc_addresses, bcc_addresses)
LOGGER.info(
'Sending Test data report to agency: %s with emails to: %s',
acronym, to_email_addresses
)
send_email(
message, subject, from_email_address,
to_email_addresses, host, port, cc_addresses,
bcc_addresses
)
elif ops:
to_email_addresses = [
email.strip() for email in contributor[0].split(' ')[1]
.translate(str.maketrans("", "", "()")).split(";")]
LOGGER.info('Sending data report to agency: {} with emails to: {}'.format(acronym, to_email_addresses))
send_email(message, specific_subject, from_email_address, to_email_addresses,
host, port, cc_addresses, bcc_addresses)
LOGGER.debug('Sent email to {} with emails to ()'.format(acronym, to_email_addresses))
LOGGER.info(
'Sending data report to agency: %s with emails to: %s',
acronym, to_email_addresses
)
send_email(
message, specific_subject, from_email_address,
to_email_addresses, host, port, cc_addresses,
bcc_addresses
)
LOGGER.debug(
'Sent email to %s with emails to %s',
acronym, to_email_addresses
)
LOGGER.info('Processing Reports have been sent')


Expand Down
22 changes: 15 additions & 7 deletions woudc_data_registry/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@


def send_email(message, subject, from_email_address, to_email_addresses,
host, port, cc_addresses=None, bcc_addresses=None, secure=False,
from_email_password=None):
host, port, cc_addresses=None, bcc_addresses=None, secure=False,
from_email_password=None):

"""
Send email
Expand Down Expand Up @@ -100,7 +101,6 @@ def send_email(message, subject, from_email_address, to_email_addresses,
]):
to_email_addresses += cc_addresses
cc = True

LOGGER.debug('bcc: {}' .format(bcc_addresses))
# bcc
if all([
Expand All @@ -116,7 +116,7 @@ def send_email(message, subject, from_email_address, to_email_addresses,
# set up the message
msg = MIMEMultipart()
msg['From'] = from_email_address
msg['To'] = ', '.join(to_email_addresses) # Join all emails into one string separated by commas
msg['To'] = ', '.join(to_email_addresses)
if cc:
msg['Cc'] = ', '.join(cc_addresses) # Add CC addresses if they exist
msg['Subject'] = subject
Expand All @@ -128,11 +128,19 @@ def send_email(message, subject, from_email_address, to_email_addresses,

# send message
try:
LOGGER.debug('Sending a data report to the groups of emails: {}'.format(to_email_addresses))
send_status = server.sendmail(msg['From'], to_email_addresses + cc_addresses, text)
LOGGER.debug(
'Sending report to {}'.format(to_email_addresses)
)
send_status = server.sendmail(
msg['From'], to_email_addresses + cc_addresses, text)
send_statuses.append(send_status)
except Exception as err:
error_msg = 'Unable to send mail from: {} to {}: {}'.format(msg['From'], msg['To'], err)
error_msg = (
'Unable to send mail from: {} to {}: {}'.format(
msg['From'], msg['To'], err
)
)

LOGGER.error(error_msg)
raise err

Expand Down

0 comments on commit 7bb2bcd

Please sign in to comment.