aboutsummaryrefslogtreecommitdiffstats
path: root/python/markit/cds.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/markit/cds.py')
-rw-r--r--python/markit/cds.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/python/markit/cds.py b/python/markit/cds.py
index dcc355d5..459d6340 100644
--- a/python/markit/cds.py
+++ b/python/markit/cds.py
@@ -5,6 +5,7 @@ import requests
import shutil
import zipfile
import time
+from env import BASE_DIR
from pandas.tseries.offsets import BDay
import pandas as pd
@@ -17,24 +18,20 @@ def convertToNone(v):
def download_cds_data(payload):
r = requests.post("https://www.markit.com/export.jsp", params=payload)
- with zipfile.ZipFile(io.BytesIO(r.content)) as z:
- f2 = open(
- os.path.join(
- os.environ["BASE_DIR"],
- "Tranche_data",
- "CDS",
- "cds eod {0}.csv".format(payload["date"]),
- ),
- "wb",
- )
- for f in z.namelist():
- if "csv" in f:
- f1 = z.open(f)
- next(f1)
- next(f1)
- shutil.copyfileobj(f1, f2)
- f1.close()
- f2.close()
+ content = io.BytesIO(r.content)
+ try:
+ with zipfile.ZipFile(content) as z:
+ fname = BASE_DIR / "Tranche_data" / "CDS" / f"cds eod {payload['date']}.csv"
+ with fname.open("wb") as f2:
+ for f in z.namelist():
+ if "csv" in f:
+ f1 = z.open(f)
+ next(f1)
+ next(f1)
+ shutil.copyfileobj(f1, f2)
+ f1.close()
+ except zipfile.BadZipFile:
+ logger.error(content.getvalue().decode())
def download_composite_data(payload, historical=False):