diff options
Diffstat (limited to 'python/markit_download.py')
| -rw-r--r-- | python/markit_download.py | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/python/markit_download.py b/python/markit_download.py index b4145c22..eb3e41b9 100644 --- a/python/markit_download.py +++ b/python/markit_download.py @@ -1,6 +1,47 @@ import requests
+import common
+import os
+import datetime
+import csv
-# r=requests.get('https://loans.markit.com/loanx/LoanXMarks.csv?LEGALENTITY=serecap&USERNAME=serecapuser&PASSWORD=Welcome1&EOD=Y')
-r = requests.get('https://loans.markit.com/loanx/LoanXFacilityUpdates.csv?LEGALENTITY=serecap&USERNAME=serecapuser&PASSWORD=Welcome1')
-for line in r.text.split('\n'):
- print line
+legal = 'serecap'
+username = 'serecapuser'
+password = 'Welcome1'
+
+workdate = str(datetime.date.today())
+
+def convertToNone(v):
+ return v if v else None
+
+r = requests.get('https://loans.markit.com/loanx/LoanXMarks.csv?LEGALENTITY={0}&USERNAME={1}&PASSWORD={2}&EOD=Y'.format(legal, username, password))
+marks_filename = os.path.join(common.root, "data", "markit", "markit_data_{0}.csv".format(workdate))
+with open(marks_filename, "wb") as fh:
+ fh.write(r.content)
+
+r = requests.get('https://loans.markit.com/loanx/LoanXFacilityUpdates.csv?LEGALENTITY={0}&USERNAME={1}&PASSWORD={2}'.format(legal, username, password))
+
+facility_filename = os.path.join(common.root, "data", "Facility files", "facility_{0}.csv".format(workdate))
+with open( facility_filename, "wb") as fh:
+ fh.write(r.content)
+
+sqlstring = "INSERT INTO markit_prices2 VALUES( {0} )".format( ",".join([ "%s" ] * 5))
+with open(marks_filename, "r") as fh:
+ reader = csv.reader(fh)
+ reader.next() # we skip the headers
+ for line in reader:
+ if line[4] == "implied":
+ line[4] = 0
+ common.cursor.execute(sqlstring, (line[0], line[2], line[3], line[4], line[1]))
+common.conn.commit()
+
+sqlstring = "INSERT INTO markit_facility VALUES( {0} )".format( ",".join(["%s"] * 13))
+with open( facility_filename, "r") as fh:
+ reader = csv.reader(fh) # we skip the headers
+ reader.next()
+ for line in reader:
+ newline = [convertToNone(v) for v in line]
+ common.cursor.execute(sqlstring, newline)
+common.conn.commit()
+
+common.cursor.close()
+common.conn.close()
|
