Comment out unused code in CreateTempTables and update_tvupdates methods for future verification; streamline set_apienv function by removing jget parameter and related logic.

This commit is contained in:
2025-12-12 13:48:05 -05:00
parent 3447ba369f
commit 99a2d78032
3 changed files with 20 additions and 34 deletions
+6 -7
View File
@@ -250,7 +250,6 @@ class CreateTempTables():
pass
self.create(Base, engine, metadata, session, self.tablelist)
session.commit()
#self.send(tablelist)
def settables(self, metadata, engine):
tablelist = []
@@ -379,12 +378,12 @@ class CreateTempTables():
schema = "updates",
extend_existing=True)
tablelist.append(countries)
tvupdates = Table('tvupdates', metadata,
Column('seriesid', BIGINT, primary_key = True),
Column('timestamp', VARCHAR(15)),
schema = "updates",
extend_existing=True)
tablelist.append(tvupdates)
# tvupdates = Table('tvupdates', metadata,
# Column('seriesid', BIGINT, primary_key = True),
# Column('timestamp', VARCHAR(15)),
# schema = "updates",
# extend_existing=True)
# tablelist.append(tvupdates)
return(tablelist)
def create(self, Base, engine, metadata, session, tablelist):
+5 -2
View File
@@ -27,8 +27,11 @@ 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:
# conn.execute(text(f"truncate table {tablename}"))
# conn.execute(tablename.insert(), updatelist)
conn.execute(text(f"truncate table {tablename}"))
for key, value in available_updates.items():
seriesid = str(key)
timestamp = value
conn.execute(text(f"INSERT INTO {tablename} (seriesid, timestamp) VALUES (:seriesid, :timestamp)"), {'seriesid': seriesid, 'timestamp': timestamp})
conn.commit()
print('Update of tvupdates table is complete.')
+9 -25
View File
@@ -7,7 +7,6 @@ import url.urls
import url.process
from tqdm import tqdm
import db.sql
import jprocessor.process
import logs.Logger
from db.functions import settype, dbmongo
from datetime import datetime
@@ -17,7 +16,7 @@ import json
response = None
def set_apienv(urls, uprocess, jget, dbengine, dbExec, updatesBase, lprint):
def set_apienv(urls, uprocess, dbengine, dbExec, updatesBase, lprint):
"""Populate updates table from the API and return available updates.
Args:
@@ -32,11 +31,10 @@ def set_apienv(urls, uprocess, jget, dbengine, dbExec, updatesBase, lprint):
Returns:
List of tuples (seriesid, timestamp) representing available updates.
"""
updatetable = updatesBase[8]
inputdata = uprocess.get_data(urls["updatesurl"])
availableupdates = jget.jconvert(inputdata)
lprint.logprint("info", f"Retrieved {len(availableupdates)} rows for processing......")
dbExec.update_tvupdates(dbengine["engine"], availableupdates, updatetable)
#updatetable = updatesBase[8]
#inputdata = uprocess.get_data(urls["updatesurl"])
#lprint.logprint("info", f"Retrieved {len(availableupdates)} rows for processing......")
#
newupdates = dbExec.rawsql_select(
dbengine["engine"],
"select seriesid,timestamp from updates.tvupdates",
@@ -88,7 +86,8 @@ 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'
# Create directories if missing so later code doesn't fail
try:
os.makedirs(LOGDIR, exist_ok=True)
@@ -116,11 +115,9 @@ def main() -> int:
TVMAZE_URLS = get_tvmaze(TVMAZEURLS)
TVDBURLS = url.urls.TVDBurls()
TVDB_URLS = get_tvdb(TVDBURLS)
countrydictionary = {}
updateRange = None
lprint.logprint("info", "Creating JSON instance for data retrieval.")
jget = jprocessor.process.Jsonload()
lprint.logprint("info", "JSON instance created.")
lprint.logprint("info", f"Update type is {options['updatetype']}")
timedifference = options["updatetype"]
@@ -132,9 +129,7 @@ def main() -> int:
ts1 = str(datetime.now()).split(".")[0]
lprint.logprint("info", "Sync start time: " + str(ts1))
print_starttime(lprint, ts1)
dboBase = dbengine["dboBase"]
dbExec = db.sql.Dbexec()
createTables = dbclass["Createtables"]
createTempTables = dbclass["CreateTemptables"]
new_updates = {}
@@ -145,12 +140,12 @@ def main() -> int:
)
tempTableList = ct.tablelist
new_updates = []
if options["apitype"].lower() == "tvmaze":
try:
new_updates = set_apienv(
TVMAZE_URLS,
uprocess,
jget,
dbengine,
dbExec,
tempTableList,
@@ -160,15 +155,6 @@ def main() -> int:
lprint.logprint("error", f"Failed to set API env: {exc}")
return 1
from cache.process import Cacher
cacher = Cacher()
try:
cacher.process(options, jget, new_updates, ROOTDIR, TVMAZE_URLS)
except Exception as exc:
lprint.logprint("error", f"Cache processing failed: {exc}")
return 1
timeDifference = options["updatetype"]
currentTimestamp = time.time()
if timeDifference.lower() == "full" or options["initload"] == "1":
@@ -258,7 +244,6 @@ def main() -> int:
except Exception:
# non-fatal; continue
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",
@@ -291,7 +276,6 @@ def main() -> int:
try:
if int(ts) == int(prev_ts):
found_path = find_file_in_multiple_dirs(f"{seriesid}.json", directory_list)
#print(f"Found path for series ID {seriesid}: {found_path}")
if len(found_path) == 8:
continue
else:
@@ -328,7 +312,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)