From 9ce052e04dd2aa21d06a37fd096a52ecea1ab36b Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Fri, 23 Sep 2022 15:06:20 +1000 Subject: [PATCH] Updating converter to pick up files copied in by nextcloud --- converter.py | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/converter.py b/converter.py index 883141d..378edaa 100644 --- a/converter.py +++ b/converter.py @@ -153,34 +153,39 @@ class Handler(watchdog.events.PatternMatchingEventHandler): logging.info("file copy has now finished") with open(event.src_path, 'r') as file: - qfx = OfxParser.parse(file, fail_fast=False) - statement, acct_name = Handler.get_statement_from_qfx(qfx) + try: + qfx = OfxParser.parse(file, fail_fast=False) + statement, acct_name = Handler.get_statement_from_qfx(qfx) - path = Path(event.src_path) - path.resolve() + path = Path(event.src_path) + path.resolve() - converted_dir = path.parent / CONVERTED_DIR - if not converted_dir.exists(): - converted_dir.mkdir() + converted_dir = path.parent / CONVERTED_DIR + if not converted_dir.exists(): + converted_dir.mkdir() - out_file = str(path.parent / CONVERTED_DIR / (acct_name + '-' + qfx.signon.dtserver + '.csv')) - Handler.write_csv(statement, out_file) + out_file = str(path.parent / CONVERTED_DIR / (acct_name + '-' + qfx.signon.dtserver + '.csv')) + Handler.write_csv(statement, out_file) - #Now move the input file to backup - archive_file_dir = path.parent / BACKUP_DIR - archive_file = (path.stem + '{:04d}' + path.suffix) - destination = Handler.unique_path(archive_file_dir, archive_file) + #Now move the input file to backup + archive_file_dir = path.parent / BACKUP_DIR + archive_file = (path.stem + '{:04d}' + path.suffix) + destination = Handler.unique_path(archive_file_dir, archive_file) - if not archive_file_dir.exists(): - archive_file_dir.mkdir() + if not archive_file_dir.exists(): + archive_file_dir.mkdir() - if not destination.exists(): - path.replace(destination) + if not destination.exists(): + path.replace(destination) + except: + logging.info("Failed to process {}".format(event.src_path)) logging.info("Processing successfully finished for {}".format(event.src_path)) - - def on_created(self, event): - logging.info('{} on {}'.format(event.event_type, event.src_path)) + + def on_modified(self, event): + logging.info('Found modified file: {}'.format(event.src_path)) + self.on_created(event) + if __name__ == "__main__":