diff options
Diffstat (limited to 'python/markit_loans.py')
| -rw-r--r-- | python/markit_loans.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/python/markit_loans.py b/python/markit_loans.py index 927c19bd..1cc99739 100644 --- a/python/markit_loans.py +++ b/python/markit_loans.py @@ -5,9 +5,7 @@ import os import datetime
import csv
import sys
-
-def convertToNone(v):
- return v if v else None
+import logging
@with_connection
def download_facility(conn, workdate, payload):
@@ -15,14 +13,16 @@ def download_facility(conn, workdate, payload): facility_filename = os.path.join(root, "data", "Facility files", "facility_{0}.csv".format(workdate))
with open( facility_filename, "wb") as fh:
fh.write(r.content)
-
sqlstring = "INSERT INTO markit_facility VALUES( {0} )".format( ",".join(["%s"] * 13))
with open( facility_filename, "r") as fh:
reader = csv.reader(fh)
- next(reader)
+ header = next(reader)
+ if 'Authentication failed' in header:
+ logging.error("Couldn't authenticate")
+ raise SystemExit
with conn.cursor() as c:
for line in reader:
- newline = tuple([convertToNone(v) for v in line])
+ newline = tuple([v or None for v in line])
c.execute(sqlstring, newline)
conn.commit()
@@ -35,11 +35,15 @@ def download_marks(conn, workdate, payload): sqlstring = "INSERT INTO markit_prices VALUES( {0} )".format( ",".join([ "%s" ] * 5))
with open(marks_filename, "r") as fh:
reader = csv.DictReader(fh)
+ if 'Authentication failed' in reader.fieldnames[0]:
+ logging.error("Couldn't authenticate")
+ raise SystemExit
with conn.cursor() as c:
for line in reader:
if line['Depth']=='implied':
line['Depth']=0
- c.execute(sqlstring, (line['LoanX ID'], line['Bid'], line['Offer'], line['Depth'], line['Mark Date']))
+ c.execute(sqlstring, (line['LoanX ID'], line['Bid'], line['Offer'],
+ line['Depth'], line['Mark Date']))
conn.commit()
@with_connection
@@ -71,7 +75,7 @@ def update_facility(conn, workdate, payload): next(reader)
with conn.cursor() as c:
for line in reader:
- newline = [convertToNone(v) for v in line] + [workdate]
+ newline = [v or None for v in line] + [workdate]
newline.pop(9) # remove the spread to maturity value
c.execute(sqlstring, newline)
conn.commit()
@@ -85,7 +89,9 @@ if __name__=="__main__": else:
workdate = datetime.date.today()
workdate = str(workdate)
-
+ logging.basicConfig(filename = '/home/share/CorpCDOs/logs/markit_loans.log',
+ level = logging.INFO,
+ format = '%(asctime)s %(levelname)s %(message)s')
payload={'LEGALENTITY': 'lmcg',
'USERNAME': 'serecapuser',
'PASSWORD': 'Welcome1'}
|
