diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/ack_checker.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/python/ack_checker.py b/python/ack_checker.py new file mode 100644 index 00000000..4b8ac068 --- /dev/null +++ b/python/ack_checker.py @@ -0,0 +1,38 @@ +import codecs +import datetime +from csv import reader +from io import BytesIO +from remote import FtpClient +from utils.db import dbconn + +dawndb = dbconn("dawndb") +ftp = FtpClient.from_creds("globeop") +ftp.client.cwd("outgoing") +date = datetime.date.today() +files = [f for f in ftp.client.nlst() if f.startswith(f"Serenitas.ALL.{date:%Y%m%d}")] +for f in files: + if "CreditDefaultSwapDeal" in f: + buf = BytesIO() + ftp.client.retrbinary("RETR " + f, buf.write) + buf.seek(0) + csv = reader(codecs.iterdecode(buf, "utf-8")) + for serenitas_id, action, dealtype, result, globeop_id, _, _ in csv: + if dealtype != "CreditDefaultSwapDeal": + continue + + with dawndb.cursor() as c: + c.execute( + "SELECT orig_attach FROM cds WHERE dealid=%s", (serenitas_id,) + ) + (attach,) = c.fetchone() + if attach is None: + continue + if action == "NEW" and result == "Loaded": + globeop_id = int(globeop_id) + serenitas_id = int(serenitas_id[5:]) + with dawndb.cursor() as c: + c.execute( + "INSERT INTO id_mapping VALUES(%s, %s, %s, %s)", + (date, "CDS", serenitas_id, globeop_id), + ) +dawndb.commit() |
