diff options
Diffstat (limited to 'python/load_intex_collateral.py')
| -rw-r--r-- | python/load_intex_collateral.py | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/python/load_intex_collateral.py b/python/load_intex_collateral.py index 6c887b03..4f937be7 100644 --- a/python/load_intex_collateral.py +++ b/python/load_intex_collateral.py @@ -22,17 +22,18 @@ conn = psycopg2.connect(database="ET", user="et_user", password="Serenitas1", ho cursor = conn.cursor() prog = re.compile("\((.*)\)") -workdate = "2012-11-30" +workdate = "2012-12-11" + with open(os.path.join(root, "data", "clo_universe_intex_" + workdate + ".txt")) as fh: dr = csv.DictReader(fh, dialect='excel-tab') deal_table = {line['Deal,Tr/CUSIP/ISIN']: datetime.strptime(line['Latest Update'], '%b %d, %Y').date() \ for line in dr if 'Paid' not in line['Latest Update']} -for dealname in os.listdir(os.path.join(root, "Collaterals_" + workdate)): +for dealname in os.listdir(os.path.join(root, "data", "Collaterals_" + workdate)): #dealname, updatedate = line.rstrip().split() # updatedate = datetime.datetime.strptime(updatedate, '%m/%d/%Y') #dealname = dealname.upper() + ",AD.txt" - with open( os.path.join(root, "Collaterals_" + workdate, dealname), "r") as fh: + with open( os.path.join(root, "data", "Collaterals_" + workdate, dealname), "r") as fh: dr = csv.DictReader(fh, dialect = 'excel-tab') dealname , ending = dealname.split(',') dealname = dealname.lower() @@ -60,7 +61,12 @@ for dealname in os.listdir(os.path.join(root, "Collaterals_" + workdate)): if line['Market Price'] != '' and isinstance(line['Market Price'], str): line['Market Price'] = float(line['Market Price'].replace(',','')) if isinstance(line['Contributed Balance'], str): - line['Contributed Balance'] = float(line['Contributed Balance'].replace(',','')) + line['Contributed Balance'] = line['Contributed Balance'].replace(',','') + if prog.match(line['Contributed Balance']): + line['Contributed Balance'] = -float(prog.match(line['Contributed Balance']).group(1)) + else: + line['Contributed Balance'] = float(line['Contributed Balance']) + try: r = [convertToNone(line[field]) for field in fields] except KeyError as detail: @@ -76,13 +82,19 @@ for dealname in os.listdir(os.path.join(root, "Collaterals_" + workdate)): except KeyError as detail: print detail pdb.set_trace() + + reinsert = False if updatedate in old_update_dates: - sqlstr = "SELECT count(*) from et_collateral where dealname = %s and updatedate= %s" + sqlstr = "SELECT count(*) FROM et_collateral where dealname = %s and updatedate= %s" cursor.execute(sqlstr, (dealname, updatedate)) currlen = cursor.fetchone()[0] if currlen <> len(data): - print dealname - if not old_update_dates or updatedate not in old_update_dates: + print "{0} has {1} rows in the database and current collateral file has {2}".format(dealname, currlen, data) + sqlstr = "DELETE FROM et_collateral where dealname = %s and updatedate = %s" + cursor.execute(sqlstr, (dealname, updatedate)) + conn.commit() + reinsert = True + if reinsert or not old_update_dates or updatedate not in old_update_dates: tag = 0 for row in data: # print dealname, row |
