Skip to content

Commit

Permalink
fix: merge.xlsx missing column data (#138)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmctune authored Oct 20, 2023
1 parent fcf3d7c commit a664850
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/hooking/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a664850

Please sign in to comment.