Refactor database metadata initialization and update JSON download logic for improved clarity and efficiency

This commit is contained in:
2026-02-06 10:36:20 -05:00
parent a49354bbcb
commit a52bd5571e
5 changed files with 91 additions and 116 deletions
+4 -34
View File
@@ -16,7 +16,7 @@ import json_downloader
response = None
def set_apienv(urls, uprocess, dbengine, dbExec, updatesBase, lprint):
def set_apienv(dbengine, dbExec, lprint):
"""Populate updates table from the API and return available updates.
Args:
@@ -86,7 +86,6 @@ def main() -> int:
#directories["CREDITSDIR"] = os.path.join(ROOTDIR, "cache", "credits") + os.sep
#directories["ALIASDIR"] = os.path.join(ROOTDIR, "cache", "aliases") + os.sep
tempdir = os.path.join(ROOTDIR, 'temp') + os.sep
updatetable = 'updates.tvupdates'
skip_file = f"{tempdir}skip_ids.txt"
# Create directories if missing so later code doesn't fail
@@ -108,10 +107,9 @@ def main() -> int:
config_options = settings.config.Config(ROOTDIR)
options = config_options.config_options
mongo_updater = dbmongo(options) # Create an instance of dbmongo
dbtype, apitype = options["dbtype"], options["apitype"]
dbs = settype(dbtype, apitype, options)
dbclass, dbengine, apiengine = dbs.dbclass, dbs.dbengine, dbs.apiengine
dbclass, dbengine = dbs.dbclass, dbs.dbengine
uprocess = url.process.Loadurl()
TVMAZEURLS = url.urls.Tvmazeurls()
TVMAZE_URLS = get_tvmaze(TVMAZEURLS)
@@ -146,12 +144,9 @@ def main() -> int:
if options["apitype"].lower() == "tvmaze":
try:
new_updates = set_apienv(
TVMAZE_URLS,
uprocess,
dbengine,
dbExec,
tempTableList,
lprint,
lprint
)
except Exception as exc: # noqa: PLC0301 - broad handler to log failures
lprint.logprint("error", f"Failed to set API env: {exc}")
@@ -337,32 +332,7 @@ def main() -> int:
url_template = TVMAZE_URLS["showurl"]
seriesid = file.replace('.json', '')
json_downloader.download_json_to_file(url_template.replace("<seriesid>", str(seriesid)), directory, f'{seriesid}.json', lprint)
# dbExec.update_tvupdates(dbengine["engine"], downloaded_updates_dict, updatetable)
# countrylisting = dbExec.rawsql_select(
# dbengine["engine"],
# "select row_id, country_name from dbo.countrydata",
# lprint
# )
# for country in countrylisting:
# country_name = country[1]
# country_id = country[0]
# countrydictionary[country_name] = country_id
# mongo_updater = dbmongo(options)
# mongo_updater.update_mongo(
# updateList,
# ROOTDIR,
# directories,
# jget,
# countrydictionary,
# dbExec,
# dbengine,
# dboBase,
# lprint,
# )
# return 0
lprint.logprint("info", "JSON download complete.")
if __name__ == "__main__":