aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/markit_red.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/python/markit_red.py b/python/markit_red.py
index f9feae46..513f08e1 100644
--- a/python/markit_red.py
+++ b/python/markit_red.py
@@ -1,7 +1,7 @@
import csv
from lxml import etree
import requests, io, zipfile, shutil
-from common import root
+import common
import os
from db import serenitasdb
@@ -11,7 +11,7 @@ def request_payload(payload):
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(root, "Tranche_data", "RED_reports"))
+ z.extract(f, path=os.path.join(common.root, "Tranche_data", "RED_reports"))
res.append(f)
return res
@@ -31,7 +31,7 @@ def download_report(report):
return r
def update_redcodes(fname):
- with open(os.path.join(root, "Tranche_data", "RED_reports", fname)) as fh:
+ with open(os.path.join(common.root, "Tranche_data", "RED_reports", fname)) as fh:
et = etree.parse(fh)
r = []
for indextype in ['HY', 'IG', 'EU']:
@@ -50,7 +50,7 @@ def update_redcodes(fname):
serenitasdb.commit()
def update_redindices(fname):
- basedir = os.path.join(root, "Tranche_Data", "Red")
+ basedir = os.path.join(common.root, "Tranche_Data", "RED_reports")
with open(os.path.join(basedir, fname)) as fh:
e = etree.parse(fh)
root = e.getroot()
@@ -59,7 +59,7 @@ def update_redindices(fname):
'ispreferred', 'isdatransactiontype', 'docclause','recorddate',
'publiccomments','weight']
for c in root.findall('index'):
- names = [c.find(tag) for tag in ['indexsubfamily', 'series', 'version']]
+ names = [c.find(tag).text for tag in ['indexsubfamily', 'series', 'version']]
with open( os.path.join(basedir, "{0}.{1}.V{2}.csv".format(*names)), "w") as fh2:
csvwriter = csv.DictWriter(fh2, fieldnames=headers)
csvwriter.writeheader()
@@ -75,3 +75,6 @@ if __name__=="__main__":
'REDIndexCodes']
fname = download_report("REDIndexCodes")
update_redcodes(fname[0])
+ f1, f2 = download_report("CredIndexAnnex")
+ update_redindices(f1)
+ update_redindices(f2)