aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/ack_checker.py86
1 files changed, 52 insertions, 34 deletions
diff --git a/python/ack_checker.py b/python/ack_checker.py
index a516ff9d..3c2269ce 100644
--- a/python/ack_checker.py
+++ b/python/ack_checker.py
@@ -5,38 +5,56 @@ 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:
- 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 action == "NEW" and result == "Loaded":
- globeop_id = int(globeop_id)
- serenitas_id = int(serenitas_id[5:])
- if dealtype == "CreditDefaultSwapDeal":
- 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
- with dawndb.cursor() as c:
- c.execute(
- "INSERT INTO id_mapping VALUES(%s, %s, %s, %s)",
- (date, "CDS", serenitas_id, globeop_id),
- )
- if dealtype == "SwaptionDeal":
- with dawndb.cursor() as c:
- c.execute(
- "UPDATE swaptions SET globeop_id=%s WHERE dealid=%s",
- (globeop_id, serenitas_id),
- )
- dawndb.commit()
+def ack_check(date: datetime.date, conn):
+ ftp = FtpClient.from_creds("globeop")
+ ftp.client.cwd("outgoing")
+ files = [
+ f for f in ftp.client.nlst() if f.startswith(f"Serenitas.ALL.{date:%Y%m%d}")
+ ]
+ for f in files:
+ 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 action == "NEW" and result == "Loaded":
+ globeop_id = int(globeop_id)
+ serenitas_id = int(serenitas_id[5:])
+ if dealtype == "CreditDefaultSwapDeal":
+ with conn.cursor() as c:
+ c.execute(
+ "SELECT orig_attach FROM cds WHERE id=%s", (serenitas_id,)
+ )
+ (attach,) = c.fetchone()
+ if attach is None:
+ continue
+
+ with conn.cursor() as c:
+ c.execute(
+ "INSERT INTO id_mapping VALUES(%s, %s, %s, %s)",
+ (date, "CDS", serenitas_id, globeop_id),
+ )
+ if dealtype == "SwaptionDeal":
+ with conn.cursor() as c:
+ c.execute(
+ "UPDATE swaptions SET globeop_id=%s WHERE dealid=%s",
+ (globeop_id, serenitas_id),
+ )
+ conn.commit()
+
+
+if __name__ == "__main__":
+ import argparse
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "workdate",
+ nargs="?",
+ type=datetime.date.fromisoformat,
+ default=datetime.date.today(),
+ help="working date",
+ )
+ args = parser.parse_args()
+ dawndb = dbconn("dawndb")
+ ack_check(args.workdate, dawndb)