diff options
| -rw-r--r-- | python/report_ops/__main__.py | 17 | ||||
| -rw-r--r-- | python/report_ops/custodians.py | 2 | ||||
| -rw-r--r-- | python/report_ops/scotia.py | 1 | ||||
| -rw-r--r-- | python/report_ops/wires.py | 63 |
4 files changed, 64 insertions, 19 deletions
diff --git a/python/report_ops/__main__.py b/python/report_ops/__main__.py index 104bafbb..53dc9773 100644 --- a/python/report_ops/__main__.py +++ b/python/report_ops/__main__.py @@ -94,18 +94,11 @@ if args.isosel_reports: logger.warning(e) if args.wire_reports: - for fund, custodians in _fund_custodians.items(): - for custodian in custodians: - report = Wire[ - ( - fund, - custodian, - ) - ] - try: - report.to_db(args.date) - except ValueError as e: - logger.warning(e) + for wire_report_cls in Wire._registry.values(): + try: + wire_report_cls.to_db(args.date) + except ValueError as e: + logger.warning(e) if args.send_to_custodians: for account in ( diff --git a/python/report_ops/custodians.py b/python/report_ops/custodians.py index b95def6e..59ef7701 100644 --- a/python/report_ops/custodians.py +++ b/python/report_ops/custodians.py @@ -200,4 +200,4 @@ class BNY(Custodian, account="BONY2"): class SCOTIA(Custodian, account="SCOTIA"): @staticmethod def download_reports(date=datetime.date.today()): - download_scotia_report(date) + return download_scotia_report(date) diff --git a/python/report_ops/scotia.py b/python/report_ops/scotia.py index 9d58c29a..5543aced 100644 --- a/python/report_ops/scotia.py +++ b/python/report_ops/scotia.py @@ -3,6 +3,7 @@ from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.support.ui import WebDriverWait import logging +import datetime from serenitas.utils.env import DAILY_DIR from serenitas.analytics.dates import prev_business_day diff --git a/python/report_ops/wires.py b/python/report_ops/wires.py index e2f4ea6f..63aca32a 100644 --- a/python/report_ops/wires.py +++ b/python/report_ops/wires.py @@ -1,14 +1,17 @@ -from dataclasses import dataclass +import datetime +from csv import DictReader +from functools import partial +from dataclasses import dataclass, field import pandas as pd from typing import Literal -import datetime + from serenitas.ops.trade_dataclasses import Deal, Ccy +from serenitas.analytics.dates import prev_business_day +from serenitas.utils.env import DAILY_DIR from typing import ClassVar -from .custodians import NT, BNY, UMB + +from .custodians import NT, BNY, UMB, SCOTIA from .misc import get_dir, dt_from_fname -from dataclasses import field -from csv import DictReader -from functools import partial _nt_to_currency = {"EURO - EUR": "EUR", "U.S. DOLLARS - USD": "USD"} @@ -65,6 +68,9 @@ class Wire(Deal, table_name="custodian_wires", deal_type="custodian_wires"): return p +Wire._registry.clear() + + class BowdstBNYWire(Wire, BNY, fund="BOWDST", custodian="BNY", dtkey="%Y%m%d%H%M%S"): @classmethod def from_report_line(cls, line: dict): @@ -155,3 +161,48 @@ class SerenitasUMBWire( continue cls.from_report_line(row_dict).stage() cls.commit() + + +class SeleneSCOTIAWire(Wire, SCOTIA, fund="ISOSEL", custodian="SCOTIA", dtkey=None): + @classmethod + def from_report_line(cls, line: dict): + return cls( + date=line["Value Date"], + entry_date=line["Posting Date"], + value_date=line["Value Date"], + pay_date=line["Value Date"], + currency=line["Curr."], + amount=line["Cr Amount"] if line["Dr/Cr"] == "Cr" else -line["Dr Amount"], + wire_details=line["Reference Data"], + unique_ref=line["Bank Ref."], + ) + + @classmethod + def to_db(cls, date): + p = cls.get_newest_report(date) + conn = cls._conn + with conn.cursor() as c: + c.execute( + "DELETE FROM custodian_wires WHERE date=%s AND fund=%s AND custodian=%s", + ( + prev_business_day(date), + cls.fund, + cls.custodian, + ), + ) + conn.commit() + df = pd.read_excel(p, skipfooter=2) + df["index"] = df.index + for row_dict in df.to_dict(orient="records"): + cls.from_report_line(row_dict).stage() + cls.commit() + + @classmethod + def get_newest_report(cls, date): + cls.download_reports(date) + REPORT_DIR = DAILY_DIR / "Selene" / "Scotia_reports" + return next( + REPORT_DIR.glob( + f"IsoSelene_{prev_business_day(date):%d-%b-%Y}_*_xlsx.JOAAPKO3.JOAAPKO1" + ) + ) |
