diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/process_queue.py | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/python/process_queue.py b/python/process_queue.py index 0bb705e7..fab0fc78 100644 --- a/python/process_queue.py +++ b/python/process_queue.py @@ -13,6 +13,7 @@ from io import StringIO from analytics import CreditIndex from analytics.utils import bus_day +from exchange import ExchangeMessage, FileAttachment from itertools import groupby from pickle import loads from bbg_helpers import init_bbg_session, retrieve_data, BBG_IP @@ -22,7 +23,6 @@ from pyisda.date import previous_twentieth from remote import FtpClient, SftpClient from utils.db import dbconn from quantlib.time.api import pydate_from_qldate, UnitedStates, Days, Date -from gmail_helpers import GmailMessage from tabulate import tabulate HEADERS_PRE = [ @@ -343,9 +343,10 @@ def process_list( buf = generate_csv( (t for t in trades if t.get("upload", True)), trade_type, fund, ) - file_path = write_buffer(buf, DAILY_DIR, trade_type, fund) + dest = get_filepath(DAILY_DIR, trade_type, fund) if upload: - upload_file(file_path) + upload_buf(buf, dest.name, fund) + dest.write_bytes(buf) except IOError: pass p.delete(key) @@ -716,11 +717,8 @@ def bond_trade_process(conn, session, trade): def send_email(trade): # send out email with trade content if trade["upload"]: - email = GmailMessage() - email.set_content(print_trade(trade)) - email["To"] = "nyops@lmcg.com" - email["Subject"] = email_subject(trade) - email.send() + email = ExchangeMessage() + email.send_email(email_subject(trade), print_trade(trade), ("nyops@lmcg.com",)) return trade @@ -848,29 +846,32 @@ def get_filepath( ) -def upload_file(file_path: pathlib.Path) -> None: - if "BBH" in file_path.name: +def upload_buf(buf: bytes, dest: str, fund: str) -> None: + if fund == "BRINKER": sftp = SftpClient.from_creds("bbh") - sftp.put(file_path) - elif file_path.name.startswith("Serenitas"): + sftp.put(buf, dest) + elif fund == "SERCGMAST": ftp = FtpClient.from_creds("globeop") ftp.client.cwd("incoming") - ftp.put(file_path) - elif file_path.name.startswith("Bowdst"): + ftp.put(buf, dest) + elif fund == "BOWDST": sftp = SftpClient.from_creds("bony") sftp.client.chdir("/inbound/cfe/") - sftp.put(file_path) - - -def write_buffer( - buf: bytes, - base_dir: pathlib.Path, - trade_type: str = "bond", - fund: str = "SERCGMAST", -): - file_path = get_filepath(base_dir, trade_type, fund) - file_path.write_bytes(buf) - return file_path + sftp.put(buf, dest) + attach = FileAttachment(dest, buf) + em = ExchangeMessage() + em.send_email( + "Trade file", + "", + to_recipients=( + "caagtradecapture@bnymellon.com", + "hm-operations@bnymellon.com", + ), + cc_recipients=("bowdoin-ops@lmcg.com",), + attachments=(FileAttachment(dest, buf),), + ) + else: + raise ValueError("unknow fund name") def email_subject(trade): |
