1
0
Fork 0
mirror of https://github.com/qurator-spk/modstool.git synced 2025-08-29 03:19:52 +02:00

🐛 Don't use bare except, check for existence of index column instead

This commit is contained in:
Mike Gerber 2025-08-21 15:54:13 +02:00
parent 1e5cfcc0e5
commit 664900635d
2 changed files with 13 additions and 4 deletions

View file

@ -452,3 +452,12 @@ def convert_db_to_parquet(con, table, index_col, output_file):
)
df.to_parquet(output_file)
def sqlite3_column_exists(con, table, col):
"""Check if column col exists in table."""
cur = con.execute(
"SELECT 1 FROM pragma_table_info(?) WHERE name = ? LIMIT 1",
(table, col)
)
return cur.fetchone() is not None

View file

@ -20,6 +20,7 @@ from .lib import (
insert_into_db_multiple,
ns,
sorted_groupby,
sqlite3_column_exists,
)
@ -643,17 +644,16 @@ def process(mets_files: list[str], output_file: str, output_page_info: str, mets
logger.exception("Exception in {}".format(mets_file))
logger.info("Writing DataFrame to {}".format(output_file))
considered_indexes = ("recordInfo_recordIdentifier", "recordIdentifier-zdb")
success = False
for considered_index in considered_indexes:
try:
if sqlite3_column_exists(con, "mods_info", considered_index):
convert_db_to_parquet(con, "mods_info", considered_index, output_file)
success = True
break
except:
pass
if not success:
raise ValueError(f"None of {considered_indexes} found")
raise ValueError(f"Can't set index, none of {considered_indexes} found")
if output_page_info:
logger.info("Writing DataFrame to {}".format(output_page_info))