diff options
Diffstat (limited to 'python/citco_ops')
| -rw-r--r-- | python/citco_ops/cash.py | 35 | ||||
| -rw-r--r-- | python/citco_ops/misc.py | 6 |
2 files changed, 9 insertions, 32 deletions
diff --git a/python/citco_ops/cash.py b/python/citco_ops/cash.py index d7ac7f51..29f73fee 100644 --- a/python/citco_ops/cash.py +++ b/python/citco_ops/cash.py @@ -2,19 +2,13 @@ from dataclasses import field, dataclass from serenitas.ops.trade_dataclasses import Deal, Fund from serenitas.analytics.dates import prev_business_day, next_business_day import datetime -import gpg from serenitas.utils.exchange import ExchangeMessage from serenitas.utils.env import DAILY_DIR import pandas as pd from serenitas.utils.db import dbconn, dawn_engine from typing import ClassVar -from .misc import get_dir - - -def dt_from_fname(f): - return datetime.datetime.strptime( - f.name.removesuffix(".csv").removesuffix(".xlsx").rsplit("_")[-1], "%Y%m%d%H%M" - ) +from .misc import get_dir, dt_from_fname +from .custodians import NT @dataclass @@ -83,30 +77,7 @@ class CashReport: cls._conn.commit() -class NTCashReport(CashReport, fund="ISOSEL", account_number="ISOS01"): - @classmethod - def download_reports(cls, date=datetime.date.today()): - em = ExchangeMessage() - for msg in em.get_msgs(path=["SeleneOps", "Passport"]): - for attach in msg.attachments: - message_time = attach.last_modified_time - if attach.name == "Attachment1.pgp" and message_time.date() == date: - dest = get_dir(message_time.date(), archived=False) - dest.mkdir(exist_ok=True, parents=True) - with attach.fp as fp: - plaintext, result, verify_result = gpg.Context().decrypt( - fp.read(), passphrase="Serenitas1" - ) - fname = ( - "custodian_wires" - if "custodian" in verify_result.file_name - else "cash" - ) - dest = dest / f"{fname}_{message_time:%Y%m%d%H%M}.csv" - with open(dest, "w") as csvFile: - text = plaintext.decode("utf-8").replace("\t", ",") - csvFile.write(text) - +class NTCashReport(CashReport, NT, fund="ISOSEL", account_number="ISOS01"): def to_db(self): p = super().to_db("cash_") df = pd.read_csv(p, on_bad_lines="warn") diff --git a/python/citco_ops/misc.py b/python/citco_ops/misc.py index 56672b07..318bb4eb 100644 --- a/python/citco_ops/misc.py +++ b/python/citco_ops/misc.py @@ -14,3 +14,9 @@ def get_dir(workdate: datetime.date, archived=True) -> pathlib.Path: / "Reports" ) return p + + +def dt_from_fname(f): + return datetime.datetime.strptime( + f.name.removesuffix(".csv").removesuffix(".xlsx").rsplit("_")[-1], "%Y%m%d%H%M" + ) |
