aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops
diff options
context:
space:
mode:
Diffstat (limited to 'python/report_ops')
-rw-r--r--python/report_ops/cash.py6
-rw-r--r--python/report_ops/custodians.py1
-rw-r--r--python/report_ops/scotia.py46
3 files changed, 33 insertions, 20 deletions
diff --git a/python/report_ops/cash.py b/python/report_ops/cash.py
index 3d2ddab2..da8709c4 100644
--- a/python/report_ops/cash.py
+++ b/python/report_ops/cash.py
@@ -98,7 +98,9 @@ class SerenitasUMBCashReport(
p = self.get_cash_report("umb_")
df = pd.read_excel(p, skiprows=3)
for row in (
- df.groupby(["Portfolio #", "Currency"]).sum()["Current Balance"].items()
+ df.groupby(["Portfolio #", "Currency"])
+ .sum(numeric_only=True)["Current Balance"]
+ .items()
):
self.stage_from_row(row)
self.commit()
@@ -119,7 +121,7 @@ class BowdstBNYCashReport(
)
for row in (
df.groupby(["Account Number", "Local Currency Code"])
- .sum()["Beginning Balance Local"]
+ .sum(numeric_only=True)["Beginning Balance Local"]
.items()
):
self.stage_from_row(row)
diff --git a/python/report_ops/custodians.py b/python/report_ops/custodians.py
index 59ef7701..7637517b 100644
--- a/python/report_ops/custodians.py
+++ b/python/report_ops/custodians.py
@@ -188,7 +188,6 @@ class BNY(Custodian, account="BONY2"):
date_part, "%Y%m%d%H%M%S"
).date()
case _:
- warnings.warn(f"Unknown report type {file_type}")
continue
p = DAILY_DIR / str(date) / "Reports" / fname
if not p.parent.exists():
diff --git a/python/report_ops/scotia.py b/python/report_ops/scotia.py
index 5543aced..fccb45a7 100644
--- a/python/report_ops/scotia.py
+++ b/python/report_ops/scotia.py
@@ -1,7 +1,10 @@
import time
+import re
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.webdriver.common.by import By
import logging
import datetime
@@ -17,10 +20,10 @@ def wait(driver):
)
-def download_report(account_username, password, report_dir):
+def download_report(account_username, password, report_dir, workdate):
driver = create_driver(report_dir)
login(driver, account_username, password)
- navigate_to_inbox(driver)
+ navigate_to_inbox(driver, workdate)
attachment_element = get_attachment_element(driver)
attachment_element.click()
fname = attachment_element.text.split()[0]
@@ -40,21 +43,30 @@ def login(driver, account_username, password):
wait(driver)
-def navigate_to_inbox(driver):
- time.sleep(1)
- login_button = driver.find_element_by_id("leftNavFolderLink")
- login_button.click()
- time.sleep(1)
- login_button = driver.find_element_by_id("leftNavInboxFolderLink")
+def navigate_to_inbox(driver, workdate):
+ wait = WebDriverWait(driver, 10)
+ login_button = wait.until(
+ EC.presence_of_element_located((By.ID, "leftNavFolderLink"))
+ )
login_button.click()
- time.sleep(1)
- elements = driver.find_elements_by_class_name("zfolder-msg-clickable")[0]
- elements.click()
- time.sleep(1)
+ wait.until(EC.presence_of_element_located((By.CLASS_NAME, "zfolder-msg")))
+ for msg in driver.find_elements_by_class_name("zfolder-msg"):
+ date_string = re.search(
+ r"\d{4}-\d{2}-\d{2}|\d{1,2}/\d{1,2}/\d{4}", msg.text
+ ).group()
+ date = datetime.datetime.strptime(date_string, "%Y-%m-%d").date()
+ if date == workdate:
+ msg.click()
+ return
+ raise ValueError(f"Could not find a file for this date {workdate}")
def get_attachment_element(driver):
- return driver.find_elements_by_class_name("zmessage-attachment-link")[0]
+ wait = WebDriverWait(driver, 10)
+ attach = wait.until(
+ EC.presence_of_element_located((By.CLASS_NAME, "zmessage-attachment-link"))
+ )
+ return attach
def create_driver(download_dir):
@@ -69,17 +81,17 @@ def create_driver(download_dir):
return webdriver.Firefox(firefox_profile=fp, options=options)
-def download_scotia_report(date):
+def download_scotia_report(workdate):
scotia_login = {"selene-ops@lmcg.com": "oeujG*UF!53o"}
for username, password in scotia_login.items():
REPORT_DIR = DAILY_DIR / "Selene" / "Scotia_reports"
try:
fname = next(
REPORT_DIR.glob(
- f"IsoSelene_{prev_business_day(date):%d-%b-%Y}_*_xlsx.JOAAPKO3.JOAAPKO1"
+ f"IsoSelene_{prev_business_day(workdate):%d-%b-%Y}_*_xlsx.JOAAPKO3.JOAAPKO1"
)
)
logger.info(f"{fname} already exists in {REPORT_DIR}")
except StopIteration: # File doesn't exist, let's get it"
- fname = download_report(username, password, REPORT_DIR)
- logger.info(f"Downloaded Scotia Report for {date}: {fname}")
+ fname = download_report(username, password, REPORT_DIR, workdate)
+ logger.info(f"Downloaded Scotia Report for {workdate}: {fname}")