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:
@@ -25,12 +25,12 @@ class Dbexec():
|
||||
]
|
||||
|
||||
# Commented out code for applying updates for now. Will re-enable later after downloads are verified.
|
||||
# print('Applying updates to table.')
|
||||
# with engine.connect() as conn:
|
||||
print('Applying updates to table.')
|
||||
with engine.connect() as conn:
|
||||
# conn.execute(text(f"truncate table {tablename}"))
|
||||
# conn.execute(tablename.insert(), updatelist)
|
||||
# conn.commit()
|
||||
# print('Update of tvupdates table is complete.')
|
||||
conn.commit()
|
||||
print('Update of tvupdates table is complete.')
|
||||
|
||||
def rawsql_select(self, engine, sqlquery, lprint):
|
||||
session = Session(engine)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ def download_json_to_file(api_url, outputdir, output_file, lprint):
|
||||
with open(f"{outputdir}{output_file}", 'w') as f:
|
||||
json.dump(data, f, indent=4)
|
||||
#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:
|
||||
lprint.logprint("info", f"Downloadinng {outputdir}{output_file} for series ID: {output_file.replace('.json', '')} failed: {e}")
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[global]
|
||||
loglevel=debug
|
||||
loglevel=info
|
||||
|
||||
[dbsettings]
|
||||
sqlserver_driver=ODBC Driver 13 for SQL Server
|
||||
|
||||
+3
-3
@@ -199,7 +199,7 @@ def main() -> int:
|
||||
# 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
|
||||
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)
|
||||
try:
|
||||
downloaded_updates_dict = {}
|
||||
@@ -257,8 +257,8 @@ def main() -> int:
|
||||
downloaded_updates_list = []
|
||||
except Exception:
|
||||
# non-fatal; continue
|
||||
pass
|
||||
del downloaded_updates_list
|
||||
lprint.logprint("warning", "Failed to save or load downloaded updates JSON.")
|
||||
#del downloaded_updates_list
|
||||
previouslisting = dbExec.rawsql_select(
|
||||
dbengine["engine"],
|
||||
"select seriesid, timestamp from updates.tvupdates order by seriesid",
|
||||
|
||||
Reference in New Issue
Block a user