1
0
Fork 0

chase: Handle both CSV schemata

Apparently, Chase has switched back to the CSV schema without the Card
column at the beginning.  Just in case they decide to flip-flop on that
field forever, we better try to handle both cases.
master
Dustin 2023-11-04 17:41:41 -05:00
parent 45b9e64ec1
commit ca8bff8fc5
1 changed files with 10 additions and 0 deletions

View File

@ -638,6 +638,16 @@ class Chase:
def firefly_import(self, csv: Path, account: int, token: str) -> None: def firefly_import(self, csv: Path, account: int, token: str) -> None:
config = copy.deepcopy(self.IMPORT_CONFIG) config = copy.deepcopy(self.IMPORT_CONFIG)
config['default_account'] = account config['default_account'] = account
with csv.open('r', encoding='utf-8') as f:
headers = f.readline()
if headers.startswith('Card'):
log.debug('Detected CSV schema with Card column')
elif headers.count(',') == 6:
log.debug('Detected CSV schema without Card column')
config['roles'].pop(0)
config['do_mapping'].pop(0)
else:
raise ValueError(f'Unexpected CSV schema: {headers}')
firefly_import(csv, config, token) firefly_import(csv, config, token)