diff options
Diffstat (limited to 'python/collateral_calc.py')
| -rw-r--r-- | python/collateral_calc.py | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/python/collateral_calc.py b/python/collateral_calc.py index 1a091238..a42a133a 100644 --- a/python/collateral_calc.py +++ b/python/collateral_calc.py @@ -3,7 +3,7 @@ import logging import pandas as pd from db import dbengine -from exchange import get_msgs, get_account +from exchange import ExchangeMessage from exchangelib import Mailbox, Message, HTMLBody from pathlib import Path from time import sleep @@ -101,9 +101,10 @@ def download_ms_emails_from_gmail(): continue def download_ms_emails(count=20): - emails = get_msgs(path=["NYops", "Margin calls MS"], - subject_filter="SERCX **Daily", - count=count) + em = ExchangeMessage() + emails = em.get_msgs(path=["NYops", "Margin calls MS"], + count=count, + subject__contains="SERCX **Daily") DATA_DIR = DAILY_DIR / "MS_reports" for msg in emails: for attach in msg.attachments: @@ -119,9 +120,10 @@ def download_ms_emails(count=20): def download_gs_emails(count=20): - emails = get_msgs(path=["NYops", "Margin calls"], - subject_filter="Margin", - count=count) + em = ExchangeMessage() + emails = em.get_msgs(path=["NYops", "Margin calls"], + count=count, + subject__contains="Margin") DATA_DIR = DAILY_DIR / "GS_reports" for msg in emails: for attach in msg.attachments: @@ -131,6 +133,19 @@ def download_gs_emails(count=20): if not p.exists(): p.write_bytes(attach.content) +def download_citi_emails(count=20): + em = ExchangeMessage() + emails = em.get_msgs(path=["NYops", "Margin Calls Citi"], + count=count, + subject__startswith="262966") + DATA_DIR = DAILY_DIR / "CITI_reports" + for msg in emails: + for attach in msg.attachments: + fname = attach.name + p = DATA_DIR / fname + if not p.exists(): + p.write_bytes(attach.content) + def baml_collateral(d): dawn_engine = dbengine("dawndb") df = pd.read_csv(DAILY_DIR / "BAML_reports" / @@ -309,7 +324,7 @@ def gs_collateral(d): return df -def send_email(account, df_ms, df_baml, df_gs): +def send_email(df_ms, df_baml, df_gs): pd.set_option('display.float_format', '{:.2f}'.format) content = HTMLBody('<html><body>' '<h3>At Morgan Stanley:</h3>' @@ -321,20 +336,16 @@ def send_email(account, df_ms, df_baml, df_gs): '</body><html>'.format(df_ms.to_html(index=False), df_baml.to_html(index=False), df_gs.to_html(index=False))) - m = Message( - account=account, - folder=account.sent, - subject='IAM booking', - body=content, - to_recipients=[Mailbox(email_address='serenitas.otc@sscinc.com')], - cc_recipients=['nyops@lmcg.com'] - ) - m.send_and_save() + em = ExchangeMessage() + em.send_email("IAM booking", content, + ['serenitas.otc@sscinc.com'], + ['nyops@lmcg.com']) if __name__ == "__main__": download_ms_emails() download_gs_emails() + download_citi_emails() d = (pd.Timestamp.today() - BDay()).normalize() #download_sftp_files(d) download_baml_files() @@ -350,5 +361,4 @@ if __name__ == "__main__": except FileNotFoundError as e: logging.info(e) df_gs = gs_collateral(d - BDay()) - account = get_account('ghorel@lmcg.com') - send_email(account, df_ms, df_baml, df_gs) + send_email(df_ms, df_baml, df_gs) |
