From 24203aff66f9d318f4b028d5cad10c9e2e111c5e Mon Sep 17 00:00:00 2001 From: Wendell Jones Date: Fri, 12 Dec 2025 07:37:19 -0500 Subject: [PATCH] Comment out SQL update logic in Dbexec class for verification; adjust sleep duration in JSON downloader to reduce server load; enhance logging in update_mongo.py for clarity on processing updates. --- db/sql.py | 13 +++++++------ json_downloader.py | 2 +- update_mongo.py | 18 +++++++----------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/db/sql.py b/db/sql.py index 09c40a3..e075903 100644 --- a/db/sql.py +++ b/db/sql.py @@ -24,12 +24,13 @@ class Dbexec(): ) ] - 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.') + # 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: + # conn.execute(text(f"truncate table {tablename}")) + # conn.execute(tablename.insert(), updatelist) + # conn.commit() + # print('Update of tvupdates table is complete.') def rawsql_select(self, engine, sqlquery, lprint): session = Session(engine) diff --git a/json_downloader.py b/json_downloader.py index 203ce28..b228505 100644 --- a/json_downloader.py +++ b/json_downloader.py @@ -16,7 +16,7 @@ def download_json_to_file(api_url, outputdir, output_file): 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(1) # Sleep for 1 second to avoid overwhelming the server + time.sleep(.5) # Sleep for 0.5 second to avoid overwhelming the server except Exception as e: print(f"Failed to download or save JSON: {e}") diff --git a/update_mongo.py b/update_mongo.py index 3b88180..e1bd163 100755 --- a/update_mongo.py +++ b/update_mongo.py @@ -5,11 +5,7 @@ import time import sys import url.urls import url.process -# import api.tvmaze.cast as mazecast -# import api.tvmaze.crew as mazecrew -# import api.tvmaze.episodes as mazeepisodes -# import api.tvmaze.series as mazeseries -from pathlib import Path +from tqdm import tqdm import db.sql import jprocessor.process import logs.Logger @@ -288,6 +284,7 @@ def main() -> int: directory_list = [] for value in directories.values(): directory_list.append(value) + print(f"Processing {len(downloaded_updates_dict)} downloaded updates against {len(previous_listing_dict)} previous listings for files needed.") for seriesid, ts in downloaded_updates_dict.items(): if seriesid in previous_listing_dict: prev_ts = previous_listing_dict[seriesid] @@ -315,8 +312,8 @@ def main() -> int: lprint.logprint("info", f"Downloadinng JSON for {len(files_needed)} series IDs.") print(f"Downloadinng JSON for {len(files_needed)} files.") - try: - for directory, filename in files_needed: + for i in tqdm(range(len(files_needed)), desc="Downloading JSON files", unit="filename"): + for directory, file in files_needed[i:i+1]: if 'credits' in directory: url_template = TVMAZE_URLS["creditsurl"] elif 'crew' in directory: @@ -329,11 +326,10 @@ def main() -> int: url_template = TVMAZE_URLS["aliasurl"] else: url_template = TVMAZE_URLS["showurl"] - seriesid = filename.replace('.json', '') + seriesid = file.replace('.json', '') json_downloader.download_json_to_file(url_template.replace("", str(seriesid)), directory, f'{seriesid}.json') - except Exception as exc: - lprint.logprint("error", f"update_cache failed: {exc}") - return 1 + + # countrylisting = dbExec.rawsql_select(