aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/baml.py28
-rw-r--r--python/collateral/baml_isda.py4
2 files changed, 11 insertions, 21 deletions
diff --git a/python/baml.py b/python/baml.py
index fab7b768..b2916417 100644
--- a/python/baml.py
+++ b/python/baml.py
@@ -7,6 +7,7 @@ from urllib.parse import urlsplit, parse_qs, urlunsplit
from serenitas.utils.db import dawn_engine
import datetime
from serenitas.analytics.dates import prev_business_day
+from collateral.baml_isda import read_secure_message
logger = logging.getLogger(__name__)
@@ -17,25 +18,14 @@ def download_messages(em):
if msg.sender == "mercury-reports@baml.com":
date = msg.subject.split("-", 1)[1]
save_dir = DAILY_DIR / date / "Reports"
- soup = BeautifulSoup(msg.body, features="lxml")
- if title := soup.find("title"):
- if title.text == "Proofpoint Encryption":
- a = soup.find("a")
- url = urlsplit(a["href"])
- query = parse_qs(url.query)
- base_url = urlunsplit(url[:2] + ("",) * 3)
- try:
- download_from_secure_id(
- query["id"][0], query["brand"][0], save_dir, base_url
- )
- except ValueError as e:
- logger.error(e)
- continue
- for attach in msg.attachments:
- if attach.name.endswith("csv"):
- p = save_dir / attach.name
- if not p.exists():
- p.write_bytes(attach.content)
+ if msg.body.body_type == "HTML":
+ read_secure_message(msg, save_dir, logger)
+ else:
+ for attach in msg.attachments:
+ if attach.name.endswith("csv"):
+ p = save_dir / attach.name
+ if not p.exists():
+ p.write_bytes(attach.content)
def load_cash_report(workdate: datetime.date):
diff --git a/python/collateral/baml_isda.py b/python/collateral/baml_isda.py
index 2d39ec1a..685c0a12 100644
--- a/python/collateral/baml_isda.py
+++ b/python/collateral/baml_isda.py
@@ -64,7 +64,7 @@ paths = {
}
-def read_secure_message(dest, logger):
+def read_secure_message(msg, dest, logger):
soup = BeautifulSoup(msg.body, features="lxml")
a = soup.find("a")
url = urlsplit(a["href"])
@@ -86,7 +86,7 @@ def download_files(em, d=None, count=20, *, fund="Serenitas", **kwargs):
for msg in emails:
match msg.sender.name:
case "us_otc_client_valuation@baml.com" | "us_otc_client_valuation@bofa.com" if msg.body.body_type == "HTML":
- read_secure_message(DATA_DIR, logger)
+ read_secure_message(msg, DATA_DIR, logger)
case "us_otc_client_valuation@baml.com" | "us_otc_client_valuation@bofa.com" | "bank_of_america_collateral_operations@bankofamerica.com":
for attach in msg.attachments: