From 001a01eb9a287884099688833b0019e18b562c9b Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Tue, 10 Dec 2024 18:04:32 -0800 Subject: [PATCH] More changes for notebook report --- jobs/notebook-report/config.py | 1 + .../monthly/reconciliation_summary.ipynb | 10 ++++------ jobs/notebook-report/notebookreport.py | 15 ++++----------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/jobs/notebook-report/config.py b/jobs/notebook-report/config.py index 8aa380f62..3c4857d8d 100644 --- a/jobs/notebook-report/config.py +++ b/jobs/notebook-report/config.py @@ -29,6 +29,7 @@ class Config(object): WEEKLY_REPORT_DATES = os.getenv("WEEKLY_REPORT_DATES", "[1]") MONTHLY_REPORT_DATES = os.getenv("MONTHLY_REPORT_DATES", "[1]") PARTNER_CODES = os.getenv("PARTNER_CODES", "CSO,VS,RPT,ESRA") + PARTNER_CODES_DISBURSEMENT = os.getenv("PARTER_CODES_DISBURSEMENT", "CSO,VS") REPORT_API_URL = os.getenv("REPORT_API_URL", "") + os.getenv("REPORT_API_VERSION", "/api/v1") NOTEBOOK_SERVICE_ACCOUNT_ID = os.getenv("NOTEBOOK_SERVICE_ACCOUNT_ID", "") NOTEBOOK_SERVICE_ACCOUNT_SECRET = os.getenv("NOTEBOOK_SERVICE_ACCOUNT_SECRET", "") diff --git a/jobs/notebook-report/monthly/reconciliation_summary.ipynb b/jobs/notebook-report/monthly/reconciliation_summary.ipynb index 3a391c3e3..40cfe4429 100644 --- a/jobs/notebook-report/monthly/reconciliation_summary.ipynb +++ b/jobs/notebook-report/monthly/reconciliation_summary.ipynb @@ -270,7 +270,7 @@ "outputs": [], "source": [ "# Define the partner codes for which the disbursement summary should be executed\n", - "partners_for_disbursement_summary = ['CSO', 'VS']\n", + "partners_for_disbursement_summary = Config.PARTNER_CODES_DISBURSEMENT.split(\",\")\n", "\n", "print(f\"Processing for partner_code: {partner_code}\")\n", "print(f\"Partners for disbursement summary: {partners_for_disbursement_summary}\")\n", @@ -320,17 +320,15 @@ }, "outputs": [], "source": [ - "if monthly_reconciliation_disbursed is not None and not monthly_reconciliation_disbursed.empty:\n", + "if partner_code in partners_for_disbursement_summary:\n", " filename_disbursed = os.path.join(os.getcwd(), 'data', f'{partner_code}_monthly_reconciliation_disbursed_' + datetime.strftime(datetime.now() - timedelta(1), '%Y-%m') + '.csv')\n", " print(f\"Saving CSV for partner_code: {partner_code} at {filename_disbursed}\")\n", " with open(filename_disbursed, 'w') as f:\n", " f.write('Monthly Reconciliation Disbursed:\\n\\n')\n", - " if monthly_reconciliation_disbursed.empty:\n", + " if monthly_reconciliation_disbursed is None or monthly_reconciliation_disbursed.empty:\n", " f.write('No Data Retrieved')\n", " else:\n", - " monthly_reconciliation_disbursed.to_csv(f, sep=',', encoding='utf-8', index=False)\n", - "else:\n", - " print(f\"Partner code {partner_code} not in the list or no data to save, skipping CSV save.\")\n" + " monthly_reconciliation_disbursed.to_csv(f, sep=',', encoding='utf-8', index=False)\n" ] }, { diff --git a/jobs/notebook-report/notebookreport.py b/jobs/notebook-report/notebookreport.py index ab1862145..c1f3776b2 100644 --- a/jobs/notebook-report/notebookreport.py +++ b/jobs/notebook-report/notebookreport.py @@ -71,9 +71,10 @@ def send_email(file_processing, emailtype, errormessage, partner_code=None): elif "reconciliation_summary" in file_processing: year_month = datetime.strftime(datetime.now() - timedelta(1), "%Y-%m") subject = "Monthly Reconciliation Stats " + year_month + ext + if partner_code in Config.PARTNER_CODES_DISBURSEMENT.split(","): + filenames.append(f"{partner_code}_monthly_reconciliation_disbursed_" + year_month + ".csv") filenames = [ f"{partner_code}_monthly_reconciliation_summary_" + year_month + ".csv", - f"{partner_code}_monthly_reconciliation_disbursed_" + year_month + ".csv", f"{partner_code}_revenue_letter.pdf", ] recipients = get_partner_recipients(file_processing, partner_code) @@ -100,6 +101,7 @@ def process_email_attachments(filenames, message): f"attachment; filename= {file}", ) file = os.path.join(os.getcwd(), r"data/") + file + print('attaching file: ', file) print(os.listdir(os.path.join(os.getcwd(), r"data/"))) with open(file, "rb") as attachment: part.set_payload(attachment.read()) @@ -125,19 +127,10 @@ def process_partner_notebooks(notebookdirectory: str, data_dir: str, partner_cod logging.info("Processing daily notebooks for partner: %s", partner_code) execute_notebook(notebookdirectory, data_dir, partner_code) - if notebookdirectory == "monthly" and today in monthly_report_dates: + if notebookdirectory == "monthly": logging.info("Processing monthly notebooks for partner: %s", partner_code) execute_notebook(notebookdirectory, data_dir, partner_code, is_monthly=True) - # Ensure both daily and monthly run on the 1st of the month - if today == 1: - if notebookdirectory == "daily": - logging.info("Also processing daily notebooks on the 1st of the month for partner: %s", partner_code) - execute_notebook(notebookdirectory, data_dir, partner_code) - elif notebookdirectory == "monthly": - logging.info("Also processing monthly notebooks on the 1st of the month for partner: %s", partner_code) - execute_notebook(notebookdirectory, data_dir, partner_code, is_monthly=True) - def process_notebooks(notebookdirectory: str, data_dir: str): """Process Notebook."""