diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/markit/__init__.py | 1 | ||||
| -rw-r--r-- | python/markit/loans.py | 37 |
2 files changed, 14 insertions, 24 deletions
diff --git a/python/markit/__init__.py b/python/markit/__init__.py index c1a1da4f..54f5c017 100644 --- a/python/markit/__init__.py +++ b/python/markit/__init__.py @@ -1 +1,2 @@ from utils.db import dbconn, with_connection +from env import DATA_DIR diff --git a/python/markit/loans.py b/python/markit/loans.py index bc5f0aaa..16c256b0 100644 --- a/python/markit/loans.py +++ b/python/markit/loans.py @@ -5,18 +5,17 @@ import requests from . import with_connection from psycopg2 import IntegrityError +from . import DATA_DIR logger = logging.getLogger(__name__) def download_facility(workdate, payload): + facility_filename = DATA_DIR / "Facility files" / f"facility_{workdate}.csv" r = requests.post( "https://loans.markit.com/loanx/LoanXFacilityUpdates.csv", params=payload ) - facility_filename = os.path.join( - os.environ["DATA_DIR"], "Facility files", "facility_{0}.csv".format(workdate) - ) - with open(facility_filename, "wb") as fh: + with facility_filename.open("wb") as fh: fh.write(r.content) @@ -24,24 +23,18 @@ def download_recupdates(workdate, payload): r = requests.post( "https://loans.markit.com/loanx/LoanXRecUpdates.csv", params=payload ) - facility_rec_update = os.path.join( - os.environ["DATA_DIR"], - "Facility files", - "facility_rec_{0}.csv".format(workdate), - ) - with open(facility_rec_update, "wb") as fh: + facility_rec_update = DATA_DIR / "Facility files" / f"facility_rec_{workdate}.csv" + with facility_rec_update.open("wb") as fh: fh.write(r.content) @with_connection("etdb") def insert_facility(conn, workdate): - facility_filename = os.path.join( - os.environ["DATA_DIR"], "Facility files", "facility_{0}.csv".format(workdate) - ) + facility_filename = DATA_DIR / "Facility files" / f"facility_{workdate}.csv" sqlstring = "INSERT INTO markit_facility VALUES( {0} )".format( ",".join(["%s"] * 13) ) - with open(facility_filename, "r") as fh: + with facility_filename.open("r") as fh: reader = csv.reader(fh) header = next(reader) if "Authentication failed" in header: @@ -62,10 +55,8 @@ def insert_facility(conn, workdate): @with_connection("etdb") def download_marks(conn, workdate, payload): r = requests.post("https://loans.markit.com/loanx/LoanXMarks.csv", params=payload) - marks_filename = os.path.join( - os.environ["DATA_DIR"], "markit", "markit_data_{0}.csv".format(workdate) - ) - with open(marks_filename, "wb") as fh: + marks_filename = DATA_DIR / "markit" / f"markit_data_{workdate}.csv" + with marks_filename.open("wb") as fh: fh.write(r.content) sqlstring = "INSERT INTO markit_prices VALUES( {0} )".format(",".join(["%s"] * 5)) with open(marks_filename, "r") as fh: @@ -96,12 +87,10 @@ def update_facility(conn, workdate, payload): sqlstring = ( "SELECT loanxid FROM markit_prices EXCEPT SELECT loanxid FROM markit_facility" ) - facility_diff_filename = os.path.join( - os.environ["DATA_DIR"], - "Facility files", - "facility_diff_{0}.csv".format(workdate), + facility_diff_filename = ( + DATA_DIR / "Facility files" / f"facility_diff_{workdate}.csv" ) - with open(facility_diff_filename, "wt") as fh: + with facility_diff_filename.open("wt") as fh: flag = False with conn.cursor() as c: c.execute(sqlstring) @@ -125,7 +114,7 @@ def update_facility(conn, workdate, payload): "VALUES( {0} )".format(",".join(["%s"] * 11)) ) try: - with open(facility_diff_filename, "r") as fh: + with facility_diff_filename.open("r") as fh: reader = csv.reader(fh) next(reader) with conn.cursor() as c: |
