diff options
Diffstat (limited to 'python/process_queue.py')
| -rw-r--r-- | python/process_queue.py | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/python/process_queue.py b/python/process_queue.py index 41b8f71f..30e45bac 100644 --- a/python/process_queue.py +++ b/python/process_queue.py @@ -2,24 +2,26 @@ import argparse import blpapi import csv import datetime +import json import logging import psycopg2 import pathlib import re import redis import sys -import task_server.config as config from io import StringIO from analytics import CreditIndex from analytics.utils import bus_day from itertools import groupby +from pathlib import Path from pickle import loads from ftplib import FTP from bbg_helpers import init_bbg_session, retrieve_data, BBG_IP from common import get_redis_queue from functools import partial +from paramiko import Transport, SFTPClient from pyisda.date import previous_twentieth from utils.db import dbconn from quantlib.time.api import pydate_from_qldate, UnitedStates, Days, Date @@ -290,6 +292,23 @@ HEADERS = { ], } +def load_credentials(name): + return json.load((Path(".credentials") / f"{name}.json").open()) + +def get_sftp_client(host, port, username, password, folder=None): + transport = Transport((host, port)) + transport.connect(username=username, password=password) + sftp = SFTPClient.from_transport(transport) + if folder is not None: + sftp.chdir(folder) + return sftp + +def get_ftp_client(host, username, password, folder=None): + ftp = FTP(host, username, password) + if folder is not None: + ftp.cwd(folder) + return ftp + def get_effective_date(d, swaption_type): if swaption_type == "CD_INDEX_OPTION": @@ -827,13 +846,16 @@ def get_filepath( def upload_file(file_path: pathlib.Path) -> None: if "BBH" in file_path.name: return - ftp = FTP("ftp.globeop.com") - ftp.login("srntsftp", config.ftp_password) - ftp.cwd("incoming") - cmd = f"STOR {file_path.name}" - with file_path.open("rb") as fh: - ftp.storbinary(cmd, fh) - + elif file_path.name.startswith("Serenitas"): + ftp = get_ftp_client(**{**load_credentials("globeop"), "folder": "incoming"}) + cmd = f"STOR {file_path.name}" + with file_path.open("rb") as fh: + ftp.storbinary(cmd, fh) + elif file_path.name.startswith("Bowdst"): + sftp = get_sftp_client(**load_credentials("bony")) + sftp.chdir("/inbound/cfe") + with file_path.open("rb") as fh: + sftp.putfo(fh, file_path.name) def write_buffer( buf: bytes, |
