diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/bowdst.py | 24 | ||||
| -rw-r--r-- | python/exchange.py | 21 |
2 files changed, 31 insertions, 14 deletions
diff --git a/python/bowdst.py b/python/bowdst.py index b897221e..0af626e5 100644 --- a/python/bowdst.py +++ b/python/bowdst.py @@ -78,23 +78,23 @@ def send_email( df_cds: pd.DataFrame, df_tranches: pd.DataFrame, ): - email = Message( - account=em._account, - folder=em._account.sent, - subject=f"{workdate} positions", - body="", - to_recipients=("reconfiles@bnymellon.com", "hm-operations@bnymellon.com"), - cc_recipients=("bowdoin-ops@lmcg.com",), - ) + attachments = [] for name, df in zip(("bonds", "cds", "tranches"), (df_bonds, df_cds, df_tranches)): buf = StringIO() df.to_csv(buf) - attachment = FileAttachment( - name=f"{workdate} {name}.csv", content=buf.getvalue().encode() + attachments.append( + FileAttachment( + name=f"{workdate} {name}.csv", content=buf.getvalue().encode() + ) ) buf.close() - email.attach(attachment) - email.send_and_save() + em.send_email( + f"{workdate} positions", + "", + to_recipients=("reconfiles@bnymellon.com", "hm-operations@bnymellon.com"), + cc_recipients=("bowdoin-ops@lmcg.com",), + attachments=attachments, + ) if __name__ == "__main__": diff --git a/python/exchange.py b/python/exchange.py index fce17e2e..efb36d40 100644 --- a/python/exchange.py +++ b/python/exchange.py @@ -1,5 +1,13 @@ -from exchangelib import Credentials, Configuration, Account, DELEGATE, Message +from exchangelib import ( + Credentials, + Configuration, + Account, + DELEGATE, + Message, + FileAttachment, +) from pathlib import Path +from typing import Tuple import json @@ -31,7 +39,14 @@ class ExchangeMessage: for msg in folder.all().order_by("-datetime_sent"): yield msg - def send_email(self, subject, body, to_recipients, cc_recipients): + def send_email( + self, + subject, + body, + to_recipients, + cc_recipients, + attach: Tuple[FileAttachment] = (), + ): m = Message( account=self._account, folder=self._account.sent, @@ -40,4 +55,6 @@ class ExchangeMessage: to_recipients=to_recipients, cc_recipients=cc_recipients, ) + for attachment in attach: + m.attach(attachment) m.send_and_save() |
