From a4292a3387ce063b03814feaf6700a7187783159 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Tue, 17 Dec 2019 16:38:04 +0100 Subject: [PATCH] Importing language csv now handles empty rows --- hugvey/tools.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hugvey/tools.py b/hugvey/tools.py index 1935e8b..5087026 100644 --- a/hugvey/tools.py +++ b/hugvey/tools.py @@ -234,7 +234,20 @@ class Toolbox: raise Exception("Not all required fieldnames are given in csv: id, translation, regex_translation") for row in reader: - node = [node for node in story if node['@id'] == row['id']][0] + if not any(row.values()): + logger.info(f"Skipping empty row") + continue + if not row['id']: + logger.critical(f"Skipping row without ID, but with data: {list(row.values())}") + continue + + try: + node = [node for node in story if node['@id'] == row['id']][0] + except Exception as e: + logger.critical(f"Exception finding node id {row}") + logger.exception(e) + raise(e) + if node['@type'] == 'Msg': if len(row['translation']) < 1 and len(node['text']) > 0: logger.warning(f"Skipping empty translation for message {node['@id']} \"{node['text']}\"")