Skip to content

Commit

Permalink
More changes for notebook report
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 committed Dec 11, 2024
1 parent c849bab commit 001a01e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions jobs/notebook-report/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down
10 changes: 4 additions & 6 deletions jobs/notebook-report/monthly/reconciliation_summary.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
},
{
Expand Down
15 changes: 4 additions & 11 deletions jobs/notebook-report/notebookreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -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."""
Expand Down

0 comments on commit 001a01e

Please sign in to comment.