73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
__author__ = 'Wendell Jones'
|
|
|
|
from tqdm import tqdm
|
|
from sqlalchemy import text
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
class Dbexec():
|
|
def __init__(self):
|
|
pass
|
|
|
|
def update_tvupdates(self, engine, available_updates, tablename):
|
|
print('Creating update transaction.')
|
|
|
|
updatelist = [
|
|
{
|
|
'seriesid': seriesid,
|
|
'timestamp': available_updates[seriesid]
|
|
}
|
|
for seriesid in tqdm(
|
|
available_updates,
|
|
desc='Updating tvupdates table',
|
|
unit='record'
|
|
)
|
|
]
|
|
|
|
# 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)
|
|
resultset = []
|
|
rs = session.execute(text(sqlquery))
|
|
for row in rs:
|
|
resultset.append(row)
|
|
session.close()
|
|
return (resultset)
|
|
|
|
def rawsql_insert(self, dbengine, sqlquery, lprint):
|
|
session = Session(dbengine)
|
|
try:
|
|
session.execute(text(sqlquery))
|
|
except Exception as e:
|
|
print(str(e))
|
|
lprint.logprint('error', 'Rollback for query: ' + sqlquery)
|
|
session.rollback()
|
|
else:
|
|
session.commit()
|
|
session.close()
|
|
|
|
def __del__(self):
|
|
pass
|
|
|
|
|
|
class SQLGenerate():
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
def read_updatetable(self, engine, lprint):
|
|
seriessql = text('''
|
|
SELECT seriesid, timestamp from updates.tvupdatedata;
|
|
''')
|
|
Dbexec.execute_rawsql(self, engine, seriessql, lprint)
|
|
|
|
def __del__(self):
|
|
pass
|