From ca8bff8fc553d87923d9a359cab435e884ec01bc Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 4 Nov 2023 17:41:41 -0500 Subject: [PATCH] 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. --- xactfetch.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xactfetch.py b/xactfetch.py index ea5cb42..586bd57 100644 --- a/xactfetch.py +++ b/xactfetch.py @@ -638,6 +638,16 @@ class Chase: def firefly_import(self, csv: Path, account: int, token: str) -> None: config = copy.deepcopy(self.IMPORT_CONFIG) 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)