aboutsummaryrefslogtreecommitdiffstats
path: root/python/custodian_wire.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/custodian_wire.py')
-rw-r--r--python/custodian_wire.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/python/custodian_wire.py b/python/custodian_wire.py
new file mode 100644
index 00000000..13970c8d
--- /dev/null
+++ b/python/custodian_wire.py
@@ -0,0 +1,62 @@
+from bowdst import get_dir, download_messages
+from csv import DictReader
+from citco_ops.bowdst import BowdstWire, IsoselWire
+from citco_ops.cash import IsoselCashReport, dt_from_fname as nt_key
+import datetime
+
+
+def dt_from_fname(f):
+ return datetime.datetime.strptime(
+ f.name.split("_")[1].split(".")[0], "%d %b %Y%H%M%S"
+ )
+
+
+def load_bowdst_wire_report(workdate: datetime.date):
+ p = max(
+ [f for f in get_dir(workdate).iterdir() if "BowdstWires" in f.name],
+ key=dt_from_fname,
+ default=None,
+ )
+ if not p: # No files available
+ return
+ with open(p) as fh:
+ reader = DictReader(fh)
+ for line in reader:
+ BowdstWire.from_nexen_line(line).stage()
+ BowdstWire.commit()
+
+
+def load_isosel_wire_report(workdate: datetime.date):
+ p = max(
+ [f for f in get_dir(workdate).iterdir() if "custodian_wires" in f.name],
+ key=nt_key,
+ default=None,
+ )
+ if not p: # No files available
+ return
+ with open(p) as fh:
+ reader = DictReader(fh)
+ for line in reader:
+ if "sponsor" in line["narrative"].lower():
+ IsoselWire.from_passport_line(line).stage()
+ IsoselWire.commit()
+
+
+if __name__ == "__main__":
+ import argparse
+ from serenitas.utils.exchange import ExchangeMessage
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "workdate",
+ nargs="?",
+ type=datetime.date.fromisoformat,
+ default=datetime.date.today(),
+ help="working date",
+ )
+ args = parser.parse_args()
+ em = ExchangeMessage()
+ download_messages(em)
+ IsoselCashReport.download_reports(args.workdate)
+ load_bowdst_wire_report(args.workdate)
+ load_isosel_wire_report(args.workdate)