diff options
Diffstat (limited to 'python/markit_red.py')
| -rw-r--r-- | python/markit_red.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/python/markit_red.py b/python/markit_red.py index 949c0578..23856894 100644 --- a/python/markit_red.py +++ b/python/markit_red.py @@ -7,10 +7,14 @@ from db import with_connection def request_payload(payload): r = requests.get('https://www.markit.com/export.jsp', params=payload) res = [] + path = os.path.join(os.environ['BASE_DIR'], "Tranche_data", "RED_reports") + if 'Delta' in payload['report']: + path = os.path.join(path, "Deltas") + with zipfile.ZipFile(io.BytesIO(r.content)) as z: for f in z.namelist(): if f.endswith("xml"): - z.extract(f, path=os.path.join(os.environ['BASE_DIR'], "Tranche_data", "RED_reports")) + z.extract(f, path=path) res.append(f) return res @@ -20,14 +24,13 @@ def download_report(report): 'password': 'password', 'version': version, 'report': report} - r = [] + if report in ['CredIndexAnnex', 'CredIndexAnnexSplit']: for family in ['CDX', 'ITRAXX-EUROPE']: payload.update({'family': family}) - r += request_payload(payload) + return request_payload(payload) else: - r += request_payload(payload) - return r + return request_payload(payload) @with_connection('serenitasdb') def update_redcodes(conn, fname): @@ -71,11 +74,14 @@ def update_redindices(fname): csvwriter.writerows(data) if __name__=="__main__": - report_list = ['REDEntity', 'REDObligation', 'REDEntityDelta', 'REDObligationDelta', - 'REDObligationPreferred', 'CredIndexAnnex', 'CredIndexAnnexSplit', - 'REDIndexCodes'] - fname = download_report("REDIndexCodes") - update_redcodes(fname[0]) - f1, f2 = download_report("CredIndexAnnex") - update_redindices(f1) - update_redindices(f2) + # fname = download_report("REDIndexCodes") + # update_redcodes(fname[0]) + # f1, f2 = download_report("CredIndexAnnex") + # update_redindices(f1) + # update_redindices(f2) + # report_list = ['REDEntity', 'REDObligation', 'REDObligationPreferred'] + # for report in report_list: + # download_report(report) + report_list = ['REDEntityDelta', 'REDObligationDelta'] + for report in report_list: + fname = download_report(report) |
