aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/collateral_calc.py48
-rw-r--r--python/exchange.py39
2 files changed, 53 insertions, 34 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)
diff --git a/python/exchange.py b/python/exchange.py
index d341cacb..18c88669 100644
--- a/python/exchange.py
+++ b/python/exchange.py
@@ -11,19 +11,28 @@ def get_account(email_address):
return Account(primary_smtp_address=email_address, config=config,
autodiscover=False, access_type=DELEGATE)
+class ExchangeMessage:
+ _account = get_account("ghorel@lmcg.com")
-def get_msgs(account=None, email_address='ghorel@lmcg.com', count=None,
- path=['GS', 'Swaptions'], subject_filter=None):
- if account is None:
- account = get_account(email_address)
- folder = account.inbox
- for p in path:
- folder /= p
- if subject_filter is not None:
- folder = folder.filter(subject__contains=subject_filter)
- if count:
- for msg in folder.all().order_by('-datetime_sent')[:count]:
- yield msg
- else:
- for msg in folder.all().order_by('-datetime_sent'):
- yield msg
+ def get_msgs(self, count=None,
+ path=['GS', 'Swaptions'], **filters):
+ folder = self._account.inbox
+ for p in path:
+ folder /= p
+ folder = folder.filter(**filters)
+ if count:
+ for msg in folder.all().order_by('-datetime_sent')[:count]:
+ yield msg
+ else:
+ for msg in folder.all().order_by('-datetime_sent'):
+ yield msg
+
+ def send_email(self, subject, body, to_recipients,
+ cc_recipients):
+ m = Message(account=self._account,
+ folder=self._account.sent,
+ subject=subject,
+ body=body,
+ to_recipients=to_recipients,
+ cc_recipients=cc_recipients)
+ m.send_and_save()