"""Perform legacy contract sync for impacted GDA accounts.""" import logging import sys sys.path.append('') logging.basicConfig(level=logging.INFO) from scripts.utils import load_csv_file # noqa: E402 from moneyhub.connectors.ows_abacus_event import OwsAbacusEvent # noqa: E402 def _get_contracts(data: list) -> list[int]: contract_ids = [int(row['contract_id']) for row in data] num_of_contracts_ids = len(contract_ids) if num_of_contracts_ids == 0: logging.error('No contract_id column found in the provided file.') exit(1) else: logging.info(f'Found {num_of_contracts_ids} contract_ids: {contract_ids}') return contract_ids if __name__ == '__main__': try: csv = load_csv_file(sys.argv[1]) except IndexError: logging.error('\t csv file not provided.') exit(1) contracts = _get_contracts(csv) event_name = 'legacy_sync_contract' for contract_id in contracts: logging.info(f'Performing legacy contract sync on contract: {contract_id}.') response = OwsAbacusEvent.create_abacus_event( event_name=event_name, target_id=contract_id, target_type='contract') logging.info(response)