diff options
Diffstat (limited to 'python/report_ops/custodians.py')
| -rw-r--r-- | python/report_ops/custodians.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/python/report_ops/custodians.py b/python/report_ops/custodians.py index 8ee2d321..7732e534 100644 --- a/python/report_ops/custodians.py +++ b/python/report_ops/custodians.py @@ -2,6 +2,7 @@ import datetime from typing import ClassVar from dataclasses import dataclass import gpg +import re from selenium.common.exceptions import ( StaleElementReferenceException, ElementNotInteractableException, @@ -10,6 +11,7 @@ from selenium.common.exceptions import ( from serenitas.utils.exchange import ExchangeMessage, FileAttachment from serenitas.utils.env import DAILY_DIR +from serenitas.utils.remote import Client from serenitas.ops.trade_dataclasses import BondDeal from serenitas.ops.funds import Service @@ -219,3 +221,22 @@ class SCOTIA(Custodian, account="SCOTIA"): TimeoutException, ): raise ValueError(f"Scotia report not ready yet for {date}") + + +class GSTXB(Custodian, account="GSTXB"): + @staticmethod + def download_reports(date=datetime.date.today()): + sftp = Client.from_creds("gstx") + pattern = r"(\d{4}-\d{2}-\d{2}T\d{2}_\d{2}_\d{2}\.\d{6})" + for f in sftp.client.listdir(): + match = re.search(pattern, f).group(1) + ts = datetime.datetime.strptime(match, "%Y-%m-%dT%H_%M_%S.%f") + if ts.date() == date: + with sftp.client.open(f) as fh: + plaintext, result, verify_result = gpg.Context().decrypt( + fh.read(), passphrase="Serenitas;1" + ) + dest = DAILY_DIR / "Serenitas" / "GSTX_reports" / f"bai_{date}.csv" + with open(dest, "w") as csvFile: + text = plaintext.decode("utf-8") + csvFile.write(text) |
