diff options
| -rw-r--r-- | python/report_ops/custodians.py | 25 | ||||
| -rw-r--r-- | python/report_ops/misc.py | 10 |
2 files changed, 10 insertions, 25 deletions
diff --git a/python/report_ops/custodians.py b/python/report_ops/custodians.py index bb939e86..51993979 100644 --- a/python/report_ops/custodians.py +++ b/python/report_ops/custodians.py @@ -100,25 +100,21 @@ def upload_to_custodian(account, trade_date, upload): class Custodian: date: datetime.date account: ClassVar[str] + em = ExchangeMessage() def __init_subclass__(cls, account): cls.account = account - @staticmethod - def em_date_filter(em, date): - return em_date_filter(em, date, date) - class NT(Custodian, account="NT"): @classmethod def download_reports(cls, date=datetime.date.today()): - em = ExchangeMessage() - for msg in em.get_msgs( - path=["SeleneOps", "Passport"], **cls.em_date_filter(em, date) + for msg in cls.em.get_msgs( + path=["SeleneOps", "Passport"], start_date=date, end_date=date ): for attach in msg.attachments: message_time = attach.last_modified_time.replace( - tzinfo=em._account.default_timezone + tzinfo=cls.em._account.default_timezone ) if attach.name == "Attachment1.pgp": dest = get_dir(message_time.date(), archived=False) @@ -141,13 +137,12 @@ class NT(Custodian, account="NT"): class UMB(Custodian, account="UMB"): @classmethod def download_reports(cls, date=datetime.date.today()): - em = ExchangeMessage() - for msg in em.get_msgs( - count=20, path=["NYops", "Powerstation"], **cls.em_date_filter(em, date) + for msg in cls.em.get_msgs( + count=20, path=["NYops", "Powerstation"], start_date=date, end_date=date ): for attach in msg.attachments: ts = attach.last_modified_time.replace( - tzinfo=em._account.default_timezone + tzinfo=cls._account.default_timezone ) dest = get_dir(date, archived=False) dest.mkdir(exist_ok=True, parents=True) @@ -164,12 +159,12 @@ class UMB(Custodian, account="UMB"): class BNY(Custodian, account="BONY2"): @classmethod def download_reports(cls, date=datetime.date.today()): - em = ExchangeMessage() - for msg in em.get_msgs( + for msg in cls.em.get_msgs( 20, path=["BowdoinOps", "Reports"], subject__startswith="Document(s) from Reporting", - **cls.em_date_filter(em, date), + start_date=date, + end_date=date, ): if msg.sender == "notify@bnymellon.com": for attach in msg.attachments: diff --git a/python/report_ops/misc.py b/python/report_ops/misc.py index 0db842bd..e86c8129 100644 --- a/python/report_ops/misc.py +++ b/python/report_ops/misc.py @@ -121,13 +121,3 @@ def dt_from_citco(filename, file_tag, dt_format): return datetime.datetime.strptime( filename.removesuffix(".csv").removeprefix(file_tag), dt_format ) - - -def em_date_filter(em: ExchangeMessage, start: datetime.date, end: datetime.date): - start = datetime.datetime.combine(start, datetime.time.min).replace( - tzinfo=em._account.default_timezone - ) - end = datetime.datetime.combine(end, datetime.time.max).replace( - tzinfo=em._account.default_timezone - ) - return {"datetime_received__gte": start, "datetime_received__lte": end} |
