From a664850af5cdc4426ceb70acd4d31a14a09009de Mon Sep 17 00:00:00 2001 From: Joey <17505625+jmctune@users.noreply.github.com> Date: Fri, 20 Oct 2023 15:15:02 -0500 Subject: [PATCH] fix: merge.xlsx missing column data (#138) If deepl or modified column is empty in merge.xlsx, populate with japanese instead. Also ensure that the connection always closes, even on failures to prevent database locking. --- app/hooking/player.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/hooking/player.py b/app/hooking/player.py index 1f1e0d8..9bf033b 100644 --- a/app/hooking/player.py +++ b/app/hooking/player.py @@ -67,11 +67,13 @@ def __write_player(self): END TRANSACTION; """ - conn = sqlite3.connect(db_file) - cursor = conn.cursor() - cursor.executescript(query) - conn.commit() - cursor.close() + try: + conn = sqlite3.connect(db_file) + cursor = conn.cursor() + cursor.executescript(query) + conn.commit() + finally: + conn.close() def __replace_with_en_names(self, string: str): @@ -133,12 +135,13 @@ def __load_dialog_into_db(self): worksheet.cell(row=row_num, column=1).value.replace("'", "''")) # if data in fixed english translation column, use it - if worksheet.cell(row=row_num, column=3).value: - en_text = self.__replace_with_en_names( - worksheet.cell(row=row_num, column=3).value.replace("'", "''")) + if fixed_text := worksheet.cell(row=row_num, column=3).value: + en_text = self.__replace_with_en_names(fixed_text.replace("'", "''")) + elif deepl_text := worksheet.cell(row=row_num, column=2).value: + en_text = self.__replace_with_en_names(deepl_text.replace("'", "''")) else: - en_text = self.__replace_with_en_names( - worksheet.cell(row=row_num, column=2).value.replace("'", "''")) + # no entry for either type. just use the japanese + en_text = ja_text query = f"INSERT INTO story_so_far (ja, en) VALUES ('{ja_text}', '{en_text}')" cursor.execute(query)