repo migration

This commit is contained in:
2025-05-20 12:02:07 -04:00
commit 29814092b7
54 changed files with 6690 additions and 0 deletions
View File
+14
View File
@@ -0,0 +1,14 @@
class cast():
def __init__(self):
pass
def listcast(self, seriesid):
pass
def listcredits(self, seriesid):
pass
def __del__(self):
pass
+15
View File
@@ -0,0 +1,15 @@
class crew():
def __init__(self):
pass
def listcrew(self, seriesid):
pass
def listcredits(self, seriesid):
pass
def __del__(self):
pass
+18
View File
@@ -0,0 +1,18 @@
class episodes():
def __init__(self):
pass
def fulllisting(self, seriesid):
pass
def seasonlist(self, seriesid, seasonnumber):
pass
def eplist(self, seriesid, seasonnumber, episodenumber):
pass
def __del__(self):
pass
+256
View File
@@ -0,0 +1,256 @@
class show():
def __init__(self):
pass
def process(self, metadata, showload, seriesid):
dataresult = []
tableresult = []
if showload == None:
pass
else:
networkid = None
try:
network = {}
for key, value in showload['network'].items():
if key == 'country':
for key, value in showload['network']['country'].items():
if key == 'name':
newkey = 'country'
network[newkey] = showload['network']['country'][key]
else:
newkey = 'country' + key
network[newkey] = showload['network']['country'][key]
else:
newkey = 'network' + key
network[newkey] = showload['network'][key]
except:
#print('Failed to insert network information.')
showload['networkid'] = 0
else:
showload.pop('network')
showload['networkid'] = network['networkid']
dataresult.append(network)
tableresult.append(metadata.tables['[updates].tvnetworknewvals'])
#insertresult = insert_data(network, tables[4])
try:
webchannel = {}
for key, value in showload['webChannel'].items():
if key == 'country':
if showload['webChannel'][key] is None:
pass
else:
for key, value in showload['webChannel']['country'].items():
newkey = 'webChannelcountry'+ key
webchannel[newkey] = value
else:
webchannel[key] = value
if key == 'name':
newkey = 'webChannel' + key
webhchannel[newkey] = value
if key == 'timezone':
newkey = 'webChannelcountry'+ key
webchannel[newkey] = value
except:
#print('Failed to insert webchannel information.')
showload['webchannelid'] = '0'
else:
showload.pop('webChannel')
showload['webchannelid'] = webchannel['id']
webchannel['webchannelname'] = webchannel['name']
webchannel['networkid'] = webchannel['id']
try:
dataresult.append(webchannel)
tableresult.append(metadata.tables['[updates].tvwebchannelnewvals'])
#insertresult = insert_data(webchannel, tables[5])
except sqlalchemy.exc.IntegrityError as e:
pass
except Exception as e:
print('Failed to insert webchannel information.')
try:
showload['seriesid'] = showload['id']
except:
pass
#print('TV Show: ' + showload['seriesname'])
try:
if showload['image']:
for key, value in showload['image'].items():
newkey = key + 'image'
showload[newkey] = value
showload.pop('image')
else:
showload.pop('image')
except:
pass
try:
if showload['externals']:
for key, value in showload['externals'].items():
showload[key] = value
showload.pop('externals')
else:
showload.pop('externals')
except KeyError as e:
pass
try:
if showload['rating']:
for key, value in showload['rating'].items():
showload['rating'] = value
if showload['schedule']:
showload['time'] = showload['schedule']['time']
showload['days'] = ", ".join(showload['schedule']['days'])
showload.pop('schedule')
except KeyError as e:
pass
try:
for key, value in showload['_links']['self'].items():
showload[key] = value
showload.pop('_links')
except KeyError as e:
pass
else:
showload.pop('id')
showload['genres'] = ", ".join(showload['genres'])
# Finish transforming to match table columns
showload['seriesname'] = showload.pop('name')
showload['tvrageid'] = showload.pop('tvrage')
showload['tvdbid'] = showload.pop('thetvdb')
showload['imdbid'] = showload.pop('imdb')
showload['serieslanguage'] = showload.pop('language')
showload['seriesstatus'] = showload.pop('status')
showload['airdays'] = showload.pop('days')
showload['airtime'] = showload.pop('time')
showload['showtype'] = showload.pop('type')
showload['overview'] = showload.pop('summary')
showload['showurl'] = showload.pop('url')
showload['apilink'] = showload.pop('href')
showload['officialsite'] = showload.pop('officialSite')
results = []
results.append([dataresult, tableresult, showload])
#results.append(tableresult)
#results.append(showload)
return (results)
def __del__(self):
pass
class cast():
def __init__(self):
pass
def process(self, cdata, seriesid):
datalist = {}
datalist['actors'] = []
datalist['characters'] = []
try:
castload = json.loads(cdata)
for idx, castdata in enumerate(castload):
actordata = {}
characterdata = {}
tcharacterdata = castload[idx]['character']
tactordata = castload[idx]['person']
try:
for key, value in tactordata.items():
if tactordata[key] is None:
pass
else:
if key == 'image':
for key, value in tactordata['image'].items():
newkey = key + 'image'
actordata[newkey] = tactordata['image'][key]
elif key == '_links':
for key, value in tactordata['_links']['self'].items():
actordata['apilink'] = tactordata['_links']['self'][key]
elif key == 'country':
for key, value in tactordata['country'].items():
newkey = 'country' + key
actordata[newkey] = tactordata['country'][key]
else:
actordata[key] = tactordata[key]
actordata['actorid'] = tactordata['id']
actordata['actorname'] = tactordata['name']
except:
print('Unable to process actor information.')
else:
actordata.pop('id')
try:
if tcharacterdata:
for key, value in tcharacterdata.items():
if key is None:
pass
else:
if tcharacterdata['image']:
characterdata['mediumimage'] = tcharacterdata['image']['medium']
characterdata['originalimage'] = tcharacterdata['image']['original']
characterdata['apilink'] = tcharacterdata['_links']['self']['href']
characterdata['tvmazeilink'] = tcharacterdata['url']
characterdata['characterid'] = tcharacterdata['id']
characterdata['charactername'] = tcharacterdata['name']
characterdata['seriesid'] = seriesid
characterdata['actorid'] = actordata['actorid']
except Exception as e:
print('Unable to process character information. -> ' + str(e))
datalist['characters'].append(characterdata)
datalist['actors'].append(actordata)
linkdata = {}
linkdata['actorid'] = actordata['actorid']
linkdata['characterid'] = characterdata['characterid']
#return(datalist)
except Exception as e:
#print('Line 389: ' + str(e))
pass
else:
return(datalist)
def __del__(self):
pass
class Episode():
def __init__(self):
pass
def process(self, epload, seriesid):
if epload:
eplist = []
try:
for epdata in epload:
epdata['seriesid'] = seriesid
if epdata['image']:
for key, value in epdata['image'].items():
newkey = key + 'image'
epdata[newkey] = value
epdata.pop('image')
else:
epdata['mediumimage'] = 'None'
epdata['originalimage'] = 'None'
epdata.pop('image')
for key, value in epdata['_links']['self'].items():
epdata['eplink'] = value
epdata.pop('_links')
epdata['episodeid'] = epdata.pop('id')
epdata['episodename'] = epdata.pop('name')
epdata['episodesummary'] = epdata.pop('summary')
epdata['episodenumber'] = epdata.pop('number')
eplist.append(epdata)
return eplist
except:
print('Unable to import episode data for for seriesid: ' + str(seriesid))
else:
return None
def __del__(self):
pass
+18
View File
@@ -0,0 +1,18 @@
class series():
def __init__(self):
pass
def search(self, searchquery):
pass
def singlesearch(self, searchquery):
pass
def idsearch(self, searchid):
pass
def __del__(self):
pass
+231
View File
@@ -0,0 +1,231 @@
import requests
import json
class Processor():
def __init__(self):
global loginurl
global refreshurl
global seriesurl
global actorurl
global episodeurl
global episodequeryurl
global episodeparamurl
global episodesummaryurl
global filterurl
global filterparamurl
global imageurl
global imagequeryurl
global imageparamurl
global username
global apikey
global userkey
global jwtoken
global refreshtoken
loginurl = 'https://api.thetvdb.com/login'
refreshurl = 'https://api.thetvdb.com/refresh_token'
seriesurl = 'https://api.thetvdb.com/series/{id}'
episodeidurl = 'https://api.thetvdb.com/episodes/{id}'
actorurl='https://api.thetvdb.com/series/{id}/actors'
episodeurl='https://api.thetvdb.com/series/{id}/episodes'
episodequeryurl='https://api.thetvdb.com/series/{id}/episodes/query'
episodeparamurl='https://api.thetvdb.com/series/{id}/episodes/query/params'
episodesummaryurl='https://api.thetvdb.com/series/{id}/episodes/summary'
filterurl='https://api.thetvdb.com/series/{id}/filter'
filterparamurl='https://api.thetvdb.com/series/{id}/filter/params'
imageurl='https://api.thetvdb.com/series/{id}/images'
imagequeryurl='https://api.thetvdb.com/series/{id}/images/query'
imageparamurl='https://api.thetvdb.com/series/{id}/images/query/params'
username = 'wpjonesnhcjc'
apikey = 'NACCS2LUWCFEFABX'
userkey = 'UUSZHUQ8CY7N31CF'
#jwtoken = login.run(self)
def __del__(self):
pass
class login():
def __init__(self):
pass
def run(self):
with requests.post(loginurl, json={"username": username, "apikey": apikey, "userkey": userkey}) as r:
response = r.json()
jwtoken = response['token']
#refreshtoken = self.refresh(jwtoken)
return(jwtoken)
def refresh(self, token):
token= "Bearer " + token
with requests.get(refreshurl, headers={'Authorization': token}) as r:
response = r.json()
refreshtoken = response['token']
return(refreshtoken)
class loadjson():
def __init__(self):
pass
def loadseries(seriesid, token):
url = seriesurl.replace('{id}', seriesid)
#print(str(url))
seriesdata = loadjson.load(url, token)
return(seriesdata)
def loadepisodes(seriesid, token):
url = episodeurl.replace('{id}', seriesid)
#print(str(url))
seriesdata = loadjson.load(url, token)
return(seriesdata)
def load(url, token):
token= "Bearer " + token
with requests.get(url, headers={'Authorization': token}) as r:
response = r.json()
return(response)
def insert(self, updater, tablename):
for key, value in updater.items():
ins = tablename.insert().values( key = value )
print(str(ins))
result = engine.execute(ins)
def populate(self, jsonurl, seriesid):
try:
with urllib.request.urlopen(jsonurl) as response:
html = response.read()
jsoninput = html
return jsoninput
except:
pass
def __del__(self):
pass
class showprocess():
def __init__(self):
pass
def process(self, metadata, tempshowload):
dataresult = []
tableresult = []
if tempshowload == None:
pass
else:
showload = json.loads(tempshowload)
networkid = None
try:
network = {}
for key, value in showload['network'].items():
if key == 'country':
for key, value in showload['network']['country'].items():
if key == 'name':
newkey = 'country'
network[newkey] = showload['network']['country'][key]
else:
newkey = 'country' + key
network[newkey] = showload['network']['country'][key]
else:
newkey = 'network' + key
network[newkey] = showload['network'][key]
except:
#print('Failed to insert network information.')
showload['networkid'] = '0'
else:
showload.pop('network')
showload['networkid'] = network['networkid']
dataresult.append(network)
tableresult.append(metadata.tables['[updates].tvnetworknewvals'])
#insertresult = insert_data(network, tables[4])
try:
webchannel = {}
for key, value in showload['webChannel'].items():
if key == 'country':
if showload['webChannel'][key] is None:
pass
else:
for key, value in showload['webChannel']['country'].items():
newkey = 'webChannelcountry'+ key
webchannel[newkey] = value
else:
webchannel[key] = value
if key == 'name':
newkey = 'webChannel' + key
webhchannel[newkey] = value
if key == 'timezone':
newkey = 'webChannelcountry'+ key
webchannel[newkey] = value
except:
#print('Failed to insert webchannel information.')
showload['webchannelid'] = '0'
else:
showload.pop('webChannel')
showload['webchannelid'] = webchannel['id']
webchannel['webchannelname'] = webchannel['name']
try:
dataresult.append(webchannel)
tableresult.append(metadata.tables['[updates].tvwebchannelnewvals'])
#insertresult = insert_data(webchannel, tables[5])
except sqlalchemy.exc.IntegrityError as e:
pass
except Exception as e:
print('Failed to insert webchannel information.')
try:
showload['seriesid'] = showload['id']
except:
pass
#print('TV Show: ' + showload['seriesname'])
if showload['image']:
for key, value in showload['image'].items():
newkey = key + 'image'
showload[newkey] = value
showload.pop('image')
else:
showload.pop('image')
if showload['externals']:
for key, value in showload['externals'].items():
showload[key] = value
showload.pop('externals')
else:
showload.pop('externals')
if showload['rating']:
for key, value in showload['rating'].items():
showload['rating'] = value
if showload['schedule']:
showload['time'] = showload['schedule']['time']
showload['days'] = ", ".join(showload['schedule']['days'])
showload.pop('schedule')
for key, value in showload['_links']['self'].items():
showload[key] = value
showload.pop('_links')
showload.pop('id')
showload['genres'] = ", ".join(showload['genres'])
# Finish transforming to match table columns
showload['seriesname'] = showload.pop('name')
showload['tvrageid'] = showload.pop('tvrage')
showload['tvdbid'] = showload.pop('thetvdb')
showload['imdbid'] = showload.pop('imdb')
showload['serieslanguage'] = showload.pop('language')
showload['seriesstatus'] = showload.pop('status')
showload['airdays'] = showload.pop('days')
showload['airtime'] = showload.pop('time')
showload['showtype'] = showload.pop('type')
showload['overview'] = showload.pop('summary')
showload['showurl'] = showload.pop('url')
showload['apilink'] = showload.pop('href')
showload['officialsite'] = showload.pop('officialSite')
results = []
results.append(dataresult)
results.append(tableresult)
results.append(showload)
return (results)