Refactor update logic in Dbexec class; adjust logging level in settings; enhance JSON downloader function call in update_mongo.py for improved error handling.

This commit is contained in:
2025-12-12 07:46:45 -05:00
parent 097225c942
commit 4f0267ecf2
4 changed files with 9 additions and 9 deletions
+4 -4
View File
@@ -25,12 +25,12 @@ class Dbexec():
] ]
# Commented out code for applying updates for now. Will re-enable later after downloads are verified. # Commented out code for applying updates for now. Will re-enable later after downloads are verified.
# print('Applying updates to table.') print('Applying updates to table.')
# with engine.connect() as conn: with engine.connect() as conn:
# conn.execute(text(f"truncate table {tablename}")) # conn.execute(text(f"truncate table {tablename}"))
# conn.execute(tablename.insert(), updatelist) # conn.execute(tablename.insert(), updatelist)
# conn.commit() conn.commit()
# print('Update of tvupdates table is complete.') print('Update of tvupdates table is complete.')
def rawsql_select(self, engine, sqlquery, lprint): def rawsql_select(self, engine, sqlquery, lprint):
session = Session(engine) session = Session(engine)
+1 -1
View File
@@ -16,7 +16,7 @@ def download_json_to_file(api_url, outputdir, output_file, lprint):
with open(f"{outputdir}{output_file}", 'w') as f: with open(f"{outputdir}{output_file}", 'w') as f:
json.dump(data, f, indent=4) json.dump(data, f, indent=4)
#print(f"JSON data saved to {outputdir}{output_file}") #print(f"JSON data saved to {outputdir}{output_file}")
time.sleep(.5) # Sleep for 0.5 second to avoid overwhelming the server time.sleep(0.5) # Sleep for 0.5 second to avoid overwhelming the server
except Exception as e: except Exception as e:
lprint.logprint("info", f"Downloadinng {outputdir}{output_file} for series ID: {output_file.replace('.json', '')} failed: {e}") lprint.logprint("info", f"Downloadinng {outputdir}{output_file} for series ID: {output_file.replace('.json', '')} failed: {e}")
+1 -1
View File
@@ -1,5 +1,5 @@
[global] [global]
loglevel=debug loglevel=info
[dbsettings] [dbsettings]
sqlserver_driver=ODBC Driver 13 for SQL Server sqlserver_driver=ODBC Driver 13 for SQL Server
+3 -3
View File
@@ -199,7 +199,7 @@ def main() -> int:
# TVMAZE_URLS is a dict of urls; use the updatesurl if available # TVMAZE_URLS is a dict of urls; use the updatesurl if available
updates_url = TVMAZE_URLS.get('updatesurl') if isinstance(TVMAZE_URLS, dict) else None updates_url = TVMAZE_URLS.get('updatesurl') if isinstance(TVMAZE_URLS, dict) else None
if updates_url: if updates_url:
json_downloader.download_json_to_file(updates_url, tempdir, out_file) json_downloader.download_json_to_file(updates_url, tempdir, out_file, lprint)
# load and convert saved JSON into a dict (id -> timestamp) # load and convert saved JSON into a dict (id -> timestamp)
try: try:
downloaded_updates_dict = {} downloaded_updates_dict = {}
@@ -257,8 +257,8 @@ def main() -> int:
downloaded_updates_list = [] downloaded_updates_list = []
except Exception: except Exception:
# non-fatal; continue # non-fatal; continue
pass lprint.logprint("warning", "Failed to save or load downloaded updates JSON.")
del downloaded_updates_list #del downloaded_updates_list
previouslisting = dbExec.rawsql_select( previouslisting = dbExec.rawsql_select(
dbengine["engine"], dbengine["engine"],
"select seriesid, timestamp from updates.tvupdates order by seriesid", "select seriesid, timestamp from updates.tvupdates order by seriesid",