diff options
Diffstat (limited to 'python/report_ops/wires.py')
| -rw-r--r-- | python/report_ops/wires.py | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/python/report_ops/wires.py b/python/report_ops/wires.py index b84331cd..baaae19d 100644 --- a/python/report_ops/wires.py +++ b/python/report_ops/wires.py @@ -25,7 +25,7 @@ class Report: def __init_subclass__(cls, table_name: str): cls._insert_fields = list(filter(cls.is_insert_field, cls.__annotations__)) place_holders = ",".join(["%s"] * len(cls._insert_fields)) - cls._sql_insert = f"INSERT INTO {table_name}({','.join(cls._insert_fields)}) VALUES({place_holders}) ON CONFLICT (unique_ref) DO NOTHING RETURNING *" + cls._sql_insert = f"INSERT INTO {table_name}({','.join(cls._insert_fields)}) VALUES({place_holders}) ON CONFLICT DO NOTHING RETURNING *" cls._insert_queue = [] @classmethod @@ -37,6 +37,23 @@ class Report: case _: return True + @classmethod + def clear(cls): + cls._insert_queue.clear() + + def stage(self): + self._insert_queue.append( + tuple([getattr(self, col) for col in self._insert_fields]) + ) + + @classmethod + def commit(cls): + conn = cls._conn + with conn.cursor() as c: + c.executemany(cls._sql_insert, cls._insert_queue) + conn.commit() + cls._insert_queue.clear() + @dataclass class WireReport(Report, table_name="custodian_wires"): @@ -52,7 +69,7 @@ class WireReport(Report, table_name="custodian_wires"): unique_ref: str dtkey: ClassVar = field(metadata={"insert": False}) - def __init_subclass__(cls, custodian, dtkey, **kwargs): + def __init_subclass__(cls, custodian, dtkey): cls.custodian = custodian cls._registry[custodian] = cls cls.dtkey = dtkey @@ -68,11 +85,6 @@ class WireReport(Report, table_name="custodian_wires"): else: self.amount = float(self.amount) - def stage(self): - self._insert_queue.append( - tuple([getattr(self, col) for col in self._insert_fields]) - ) - @classmethod def get_report(cls, date, fund, prefix=None): report_dir = get_dir(date) @@ -89,14 +101,6 @@ class WireReport(Report, table_name="custodian_wires"): ) return p - @classmethod - def commit(cls): - conn = cls._conn - with conn.cursor() as c: - c.executemany(cls._sql_insert, cls._insert_queue) - conn.commit() - cls._insert_queue.clear() - class BNYWireReport(WireReport, custodian="BNY", dtkey="%Y%m%d%H%M%S"): @classmethod @@ -147,8 +151,8 @@ class NTWireReport(WireReport, custodian="NT", dtkey="%Y%m%d%H%M"): if "sponsor" in line["narrative"].lower(): yield line - @classmethod - def nt_to_enum(cls, ccy): + @staticmethod + def nt_to_enum(ccy): _mapping = {"EURO - EUR": "EUR", "U.S. DOLLARS - USD": "USD"} return _mapping[ccy] |
