diff options
Diffstat (limited to 'python/collateral')
| -rw-r--r-- | python/collateral/common.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/python/collateral/common.py b/python/collateral/common.py index 11cc037c..abbab66b 100644 --- a/python/collateral/common.py +++ b/python/collateral/common.py @@ -4,6 +4,7 @@ import subprocess from bs4 import BeautifulSoup import pandas as pd from exchangelib import HTMLBody +from io import StringIO from sqlalchemy.engine import Engine logger = logging.getLogger(__name__) @@ -108,20 +109,20 @@ def send_email(d: datetime.date, df: pd.DataFrame) -> None: "CS": "Credit Suisse", "JPM": "JP Morgan", } - html = "<html><body>" + buf = StringIO() + buf.write("<html><body>\n") for cp, df in df.groupby(level="broker"): name = cp_mapping[cp] + buf.write(f"<h3> At {name}:</h3>\n") try: - html += f"<h3> At {name}:</h3>\n{df.loc[cp].to_html(index=False)}" + df.loc[cp].to_html(buf, index=False) except AttributeError: - html += ( - f"<h3> At {name}:</h3>\n{df.loc[cp].to_frame().T.to_html(index=False)}" - ) - html += "</body/></html>" + df.loc[cp].to_frame().T.to_html(buf, index=False) + buf.write("</body/></html>") em = ExchangeMessage() em.send_email( f"IAM booking {d:%Y-%m-%d}", - HTMLBody(html), + HTMLBody(buf.getvalue()), ["serenitas.otc@sscinc.com"], ["nyops@lmcg.com"], ) |
