diff options
Diffstat (limited to 'python/markit/cds.py')
| -rw-r--r-- | python/markit/cds.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/python/markit/cds.py b/python/markit/cds.py index e080a015..a56fb5e3 100644 --- a/python/markit/cds.py +++ b/python/markit/cds.py @@ -7,6 +7,7 @@ import zipfile import time
from pandas.tseries.offsets import BDay
import pandas as pd
+
logger = logging.getLogger(__name__)
@@ -15,10 +16,17 @@ def convertToNone(v): def download_cds_data(payload):
- r = requests.post('https://www.markit.com/export.jsp', params=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")
+ 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)
@@ -32,19 +40,24 @@ def download_cds_data(payload): def download_composite_data(payload, historical=False):
# if historical, we want to maintain the invariant mtime(f)== payload['date'] + BDay(1)
if historical:
- ts = (pd.Timestamp(payload['date']) + BDay(1)).timestamp()
- for report in ['COMPOSITES', 'TRANCHE_COMPOSITES']:
- for family in ['CDX', 'ITRAXX-EUROPE']:
- payload.update({'family': family, 'report': report})
+ ts = (pd.Timestamp(payload["date"]) + BDay(1)).timestamp()
+ for report in ["COMPOSITES", "TRANCHE_COMPOSITES"]:
+ for family in ["CDX", "ITRAXX-EUROPE"]:
+ payload.update({"family": family, "report": report})
while True:
- r = requests.post('https://www.markit.com/export.jsp', params=payload)
+ r = requests.post("https://www.markit.com/export.jsp", params=payload)
try:
with zipfile.ZipFile(io.BytesIO(r.content)) as z:
for f in z.namelist():
if "csv" in f:
- path = z.extract(f, path=os.path.join(os.environ['BASE_DIR'],
- "Tranche_data",
- "Composite_reports"))
+ path = z.extract(
+ f,
+ path=os.path.join(
+ os.environ["BASE_DIR"],
+ "Tranche_data",
+ "Composite_reports",
+ ),
+ )
if historical:
os.utime(path, (ts, ts))
except zipfile.BadZipfile:
|
