Skip to content

Commit

Permalink
Refactor: Remove print statements and enhance error logging in postma…
Browse files Browse the repository at this point in the history
…rk_nudge_report.py

- Eliminated print statements from various functions to streamline error handling.
- Improved error logging by ensuring all exceptions are logged consistently.
- Maintained functionality for generating and sending community reports via Postmark API.
  • Loading branch information
abdullai-t committed Dec 12, 2024
1 parent c75cf00 commit 58ce020
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/task_queue/nudges/postmark_nudge_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def get_stats_from_postmark(tag, start, end):
response = requests.get(url, headers=headers)
return response
except Exception as e:
print(f"Error in get_stats_from_postmark: {str(e)}")
log.error(f"Error in get_stats_from_postmark: {str(e)}")
return None

Expand All @@ -39,7 +38,6 @@ def get_community_admins(community):
name_and_emails[email] = name
return name_and_emails
except Exception as e:
print(f"Error in get_community_admins: {str(e)}")
log.error(f"Error in get_community_admins: {str(e)}")
return {}

Expand All @@ -54,7 +52,6 @@ def generate_csv_file(rows):

return response.content
except Exception as e:
print(f"Error in generate_csv_file: {str(e)}")
log.error(f"Error in generate_csv_file: {str(e)}")
return None

Expand Down Expand Up @@ -112,7 +109,6 @@ def generate_community_report_data(community, period=30):

return rows, filename
except Exception as e:
print(f"Error in generate_community_report_data: {str(e)}")
log.error(f"Error in generate_community_report_data: {str(e)}")
return [], ""

Expand All @@ -126,8 +122,7 @@ def send_email(name, email):
send_massenergize_email_with_attachments(
DATA_DOWNLOAD_TEMPLATE,
temp_data,
["[email protected]"],
# [email],
[email],
report,
filename,
None
Expand All @@ -140,16 +135,12 @@ def send_email(name, email):
for email, name in admins.items():
send_email(name, email)
except Exception as e:
print(f"Error in send_community_report: {str(e)}")
log.error(f"Error in send_community_report: {str(e)}")



def send_user_requested_postmark_nudge_report(community_id, email, period=45):
try:
print("== com = ", community_id)
print("== email ===", email)

if email and community_id:
user = UserProfile.objects.filter(email=email).first()
community = Community.objects.filter(id=community_id, is_published=True).first()
Expand All @@ -159,7 +150,6 @@ def send_user_requested_postmark_nudge_report(community_id, email, period=45):
report_file = generate_csv_file(rows=rows)
send_community_report(report_file, community, file_name, user)
except Exception as e:
print(f"Error in send_user_requested_nudge: {str(e)}")
log.error(f"Error in send_user_requested_nudge: {str(e)}")


Expand All @@ -174,5 +164,4 @@ def generate_postmark_nudge_report(task=None):
return True
except Exception as e:
log.error(f"Error in Nudge report main func: {str(e)}")
print(f"Error in Nudge report main func: {str(e)}")
return False

0 comments on commit 58ce020

Please sign in to comment.