repo migration
This commit is contained in:
+401
@@ -0,0 +1,401 @@
|
||||
import sqlalchemy
|
||||
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, Sequence, text, UniqueConstraint
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.schema import MetaData
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.types import *
|
||||
|
||||
class Tables():
|
||||
def __init__(self):
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global metadata
|
||||
global engine
|
||||
global session
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global tvupdates
|
||||
global newseriesdata
|
||||
global actorlinks
|
||||
global tablelist
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
class Createtables():
|
||||
|
||||
def __init__(self, session, metadata, engine):
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
session.commit()
|
||||
#self.send(tablelist)
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
newseriesdata = Table('seriesdata', metadata,
|
||||
Column('id', BIGINT, Sequence('seriesdata_id_seq'), primary_key = True),
|
||||
Column('seriesid',INTEGER, unique=True),
|
||||
Column('tvdbid', String(25)),
|
||||
Column('tvrageid', String(25)),
|
||||
Column('imdbid', String(25)),
|
||||
Column('serieslanguage', String(25)),
|
||||
Column('genres', String(75)),
|
||||
Column('seriesname', String(150)),
|
||||
Column('seriesstatus', String(25)),
|
||||
Column('premiered', String(25)),
|
||||
Column('airdays', String(72)),
|
||||
Column('airtime', String(25)),
|
||||
Column('runtime', String(25)),
|
||||
Column('rating', String(25)),
|
||||
Column('showtype',TEXT),
|
||||
Column('overview',TEXT),
|
||||
Column('mediumimage',TEXT),
|
||||
Column('originalimage',TEXT),
|
||||
Column('weight',INTEGER),
|
||||
Column('networkid', BIGINT),
|
||||
Column('webchannel', BIGINT),
|
||||
Column('officalsite',TEXT),
|
||||
Column('showurl',TEXT),
|
||||
Column('apilink',TEXT),
|
||||
Column('previousepisode',TEXT),
|
||||
Column('nextepisode',TEXT),
|
||||
schema = "dbo")
|
||||
tablelist.append(newseriesdata)
|
||||
newactordata = Table('actordata', metadata,
|
||||
Column('id', BIGINT, Sequence('actordata_id_seq'), primary_key = True),
|
||||
Column('actorid', INTEGER, unique=True),
|
||||
Column('actorname', VARCHAR(72)),
|
||||
Column('countryname', VARCHAR(144)),
|
||||
Column('countrytimezone', VARCHAR(72)),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(6)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('countrycode', VARCHAR(12)),
|
||||
schema = "dbo")
|
||||
tablelist.append(newactordata)
|
||||
newepdata = Table('epdata', metadata,
|
||||
Column('id', BIGINT, Sequence('epdata_id_seq'), primary_key = True),
|
||||
Column('episodeid', INTEGER),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('season', INTEGER),
|
||||
Column('episodenumber', INTEGER),
|
||||
Column('episodename', TEXT),
|
||||
Column('airdate', VARCHAR(32)),
|
||||
Column('airtime', VARCHAR(32)),
|
||||
Column('episodesummary', TEXT),
|
||||
Column('airstamp', VARCHAR(32)),
|
||||
Column('runtime', VARCHAR(6)),
|
||||
Column('eplink', TEXT),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
schema = "dbo")
|
||||
tablelist.append(newepdata)
|
||||
newcastdata = Table('castdata', metadata,
|
||||
Column('id', BIGINT, Sequence('castdata_id_seq'), primary_key = True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('characterid', INTEGER),
|
||||
Column('actorid', INTEGER),
|
||||
Column('charactername', INTEGER),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('tvmazeilink', TEXT),
|
||||
schema = "dbo")
|
||||
tablelist.append(newcastdata)
|
||||
tvnetworks = Table('tvnetworkdata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('networkid', String(12)),
|
||||
Column('networkname', String(255)),
|
||||
Column('country', String(255)),
|
||||
Column('countrycode', String(4)),
|
||||
Column('countrytimezone', String(25)),
|
||||
schema = "dbo")
|
||||
tablelist.append(tvnetworks)
|
||||
tvwebchannels = Table('tvwebchanneldata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('webchannelname', String(255)),
|
||||
Column('webchannelcountrycode', String(4)),
|
||||
Column('webchannelcountryname', String(255)),
|
||||
Column('webchannelcountrytimezone', String(4)),
|
||||
schema = "dbo")
|
||||
tablelist.append(tvwebchannels)
|
||||
countries = Table('countrydata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('name', String(255)),
|
||||
Column('code', String(255)),
|
||||
Column('timezone', String(255)),
|
||||
UniqueConstraint('name', 'timezone', name='tz_name_uk'),
|
||||
schema = "dbo")
|
||||
tablelist.append(countries)
|
||||
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
print('Creating Data Tables')
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
for table in tablelist:
|
||||
try:
|
||||
#print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
class TempTables():
|
||||
|
||||
def __init__(self, session, metadata, engine, tablelist):
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
#session.commit()
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
tvnetworknewvals = Table('tvnetworknewvals', metadata,
|
||||
Column('id', BIGINT, Sequence('network_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvnetworknewvals)
|
||||
tvwebchannelnewvals = Table('tvwebchannelnewvals', metadata,
|
||||
Column('id', BIGINT, Sequence('webchannel_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(4)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvwebchannelnewvals)
|
||||
tvupdates = Table('tvupdates', metadata,
|
||||
Column('seriesid', BIGINT, primary_key = True),
|
||||
Column('timestamp', VARCHAR(15)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvupdates)
|
||||
tvupdatedata = Table('tvupdatedata', metadata,
|
||||
Column('seriesid', BIGINT, primary_key = True),
|
||||
Column('timestamp', VARCHAR(15)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvupdatedata)
|
||||
newactorlinks = Table('newactorlinks', metadata,
|
||||
Column('id', BIGINT, Sequence('tempepisodejson_id_seq'), primary_key = True),
|
||||
Column('actorid', INTEGER),
|
||||
Column('characterid', INTEGER),
|
||||
schema = "updates")
|
||||
tablelist.append(newactorlinks)
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
tablelist.remove(tablelist[6])
|
||||
print('Creating Temporary JSON Tables')
|
||||
try:
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
except sqlalchemy.exc.ProgrammingError as pe:
|
||||
pass
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
for table in tablelist:
|
||||
if 'tvupdatedata' in table.description:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
#print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
#session.commit()
|
||||
|
||||
class CreateTempTables():
|
||||
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global metadata
|
||||
global engine
|
||||
global session
|
||||
|
||||
global tablelist
|
||||
|
||||
def __init__(self, session, metadata, engine):
|
||||
# Need to create schema if it does not exist
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
session.commit()
|
||||
#self.send(tablelist)
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
newseriesdata = Table('newseriesdata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('seriesid',INTEGER, unique=True),
|
||||
Column('thetvdb', String(25)),
|
||||
Column('tvrage', String(25)),
|
||||
Column('imdb', String(25)),
|
||||
Column('language', String(25)),
|
||||
Column('genres', String(75)),
|
||||
Column('name', String(150)),
|
||||
Column('status', String(25)),
|
||||
Column('premiered', String(25)),
|
||||
Column('days', String(72)),
|
||||
Column('time', String(25)),
|
||||
Column('runtime', String(25)),
|
||||
Column('rating', String(25)),
|
||||
Column('type',TEXT),
|
||||
Column('summary',TEXT),
|
||||
Column('medium',TEXT),
|
||||
Column('original',TEXT),
|
||||
Column('weight',INTEGER),
|
||||
Column('networkid', BIGINT),
|
||||
Column('webchannelid', BIGINT),
|
||||
Column('officalsite',TEXT),
|
||||
Column('url',TEXT),
|
||||
Column('serieslink',TEXT),
|
||||
Column('previousepisode',TEXT),
|
||||
Column('nextepisode',TEXT),
|
||||
schema="updates",
|
||||
extend_existing=True)
|
||||
tablelist.append(newseriesdata)
|
||||
newactordata = Table('newactordata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('actorid', INTEGER),
|
||||
Column('actorname', VARCHAR(72)),
|
||||
Column('name', VARCHAR(72)),
|
||||
Column('countryname', VARCHAR(72)),
|
||||
Column('countrytimezone', VARCHAR(72)),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(6)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('countrycode', VARCHAR(12)),
|
||||
schema="updates",
|
||||
extend_existing=True)
|
||||
tablelist.append(newactordata)
|
||||
NEWEPDATA_ID = Sequence('newepdata_id_seq', start=1)
|
||||
newepdata = Table('newepdata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('episodeid', INTEGER),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('season', INTEGER),
|
||||
Column('episodenumber', INTEGER),
|
||||
Column('episodename', TEXT),
|
||||
Column('airdate', VARCHAR(32)),
|
||||
Column('airtime', VARCHAR(32)),
|
||||
Column('episodesummary', TEXT),
|
||||
Column('airstamp', VARCHAR(32)),
|
||||
Column('runtime', VARCHAR(6)),
|
||||
Column('eplink', TEXT),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
schema="updates",
|
||||
extend_existing=True)
|
||||
tablelist.append(newepdata)
|
||||
newcastdata = Table('newcastdata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('characterid', INTEGER),
|
||||
Column('actorid', INTEGER),
|
||||
Column('url', TEXT),
|
||||
Column('charactername', VARCHAR(128)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('tvmazeilink', TEXT),
|
||||
Column('playingself', CHAR),
|
||||
Column('voice', CHAR),
|
||||
schema="updates",
|
||||
extend_existing=True)
|
||||
tablelist.append(newcastdata)
|
||||
newcrewdata = Table('newcrewdata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('crewid', INTEGER),
|
||||
Column('type', VARCHAR(128)),
|
||||
Column('url', TEXT),
|
||||
Column('name', VARCHAR(256)),
|
||||
Column('countryid', INTEGER),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(24)),
|
||||
Column('medium', TEXT),
|
||||
Column('original', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
UniqueConstraint('seriesid', 'crewid', 'type', name='crew_unique'),
|
||||
schema="updates",
|
||||
extend_existing=True)
|
||||
tablelist.append(newcrewdata)
|
||||
tvnetworks = Table('tvnetworkdata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates",
|
||||
extend_existing=True)
|
||||
tablelist.append(tvnetworks)
|
||||
tvwebchannels = Table('tvwebchanneldata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates",
|
||||
extend_existing=True)
|
||||
tablelist.append(tvwebchannels)
|
||||
countries = Table('newcountrydata', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('name', String(255)),
|
||||
Column('code', String(255)),
|
||||
Column('timezone', String(255)),
|
||||
UniqueConstraint('name', 'timezone', name='tz_name_uk'),
|
||||
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)
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
print('Creating Temporary Data Tables')
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
print('Dropping temporary update tables.')
|
||||
for table in tablelist:
|
||||
try:
|
||||
print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
@@ -0,0 +1,566 @@
|
||||
CREATE SCHEMA dbo;
|
||||
|
||||
ALTER SCHEMA dbo OWNER TO postgres;
|
||||
|
||||
CREATE SCHEMA updates;
|
||||
|
||||
ALTER SCHEMA updates OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.actordata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.actordata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.castdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.castdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.countrydata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.countrydata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.crewdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.crewdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.epdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.epdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.epdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.epdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.seriesdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.seriesdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.tvnetworkdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.tvnetworkdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.tvwebchanneldata_id_seq
|
||||
AS integer START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
MAXVALUE 2147483647
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.tvwebchanneldata_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.webchanneldata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.webchanneldata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.actordata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.actordata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.castdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.castdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.countrydata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.countrydata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.crewdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.crewdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.seriesdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.seriesdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvnetworkdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvnetworkdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvupdates_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvupdates_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvwebchanneldata_id_seq
|
||||
AS integer START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
MAXVALUE 2147483647
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvwebchanneldata_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.webchanneldata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.webchanneldata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE TABLE dbo.actordata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.actordata_row_id_seq'::regclass),
|
||||
actorid integer,
|
||||
actorname character varying(72),
|
||||
countryname character varying(144),
|
||||
countrytimezone character varying(72),
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(6),
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
url text,
|
||||
countrycode character varying(12));
|
||||
|
||||
ALTER TABLE dbo.actordata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.actordata_row_id_seq OWNED BY dbo.actordata.row_id;
|
||||
|
||||
CREATE TABLE dbo.castdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.castdata_row_id_seq'::regclass),
|
||||
seriesid integer,
|
||||
characterid integer,
|
||||
actorid integer,
|
||||
charactername integer,
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
tvmazeilink text);
|
||||
|
||||
ALTER TABLE dbo.castdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.castdata_row_id_seq OWNED BY dbo.castdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.countrydata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.countrydata_row_id_seq'::regclass),
|
||||
country_name character varying(255),
|
||||
country_code character varying(255),
|
||||
country_timezone character varying(255));
|
||||
|
||||
ALTER TABLE dbo.countrydata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.countrydata_row_id_seq OWNED BY dbo.countrydata.row_id;
|
||||
|
||||
CREATE TABLE dbo.crewdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.crewdata_row_id_seq'::regclass),
|
||||
crewid integer,
|
||||
crew_type character varying(128),
|
||||
name character varying(255),
|
||||
_links_self_href text,
|
||||
country_name text,
|
||||
country_code text,
|
||||
country_timezone text,
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(24),
|
||||
image_medium text,
|
||||
image_original text,
|
||||
updated text,
|
||||
url text);
|
||||
|
||||
ALTER TABLE dbo.crewdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.crewdata_row_id_seq OWNED BY dbo.crewdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.epdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.epdata_row_id_seq'::regclass),
|
||||
episodeid integer,
|
||||
seriesid integer,
|
||||
season integer,
|
||||
episode_number integer,
|
||||
episode_name text,
|
||||
airdate character varying(32),
|
||||
airtime character varying(32),
|
||||
summary text,
|
||||
airstamp character varying(32),
|
||||
runtime character varying(6),
|
||||
eplink text,
|
||||
image_medium text,
|
||||
url text,
|
||||
image_original text,
|
||||
episode_type text,
|
||||
rating_average text,
|
||||
_links_self_href text,
|
||||
_links_show_href text,
|
||||
_links_show_name text);
|
||||
|
||||
ALTER TABLE dbo.epdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.epdata_row_id_seq OWNED BY dbo.epdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.seriesdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.seriesdata_row_id_seq'::regclass),
|
||||
_links_previousepisode_href text,
|
||||
_links_previousepisode_name text,
|
||||
_links_nextepisode_href text,
|
||||
_links_nextepisode_name text,
|
||||
_links_self_href text,
|
||||
averageruntime text,
|
||||
dvdcountry text,
|
||||
series_name text,
|
||||
ended date,
|
||||
externals_imdb text,
|
||||
externals_thetvdb text,
|
||||
externals_tvrage text,
|
||||
genres text,
|
||||
seriesid text,
|
||||
image_medium text,
|
||||
image_original text,
|
||||
language_name text,
|
||||
network_id text,
|
||||
network_name text,
|
||||
officialsite text,
|
||||
network_officialsite text,
|
||||
network_country_code text,
|
||||
network_country_name text,
|
||||
network_country_timezone text,
|
||||
premiered text,
|
||||
rating_average text,
|
||||
runtime text,
|
||||
schedule_days text,
|
||||
schedule_time text,
|
||||
status text,
|
||||
summary text,
|
||||
series_type text,
|
||||
updated text,
|
||||
url text,
|
||||
webchannel_id integer,
|
||||
webchannel_name text,
|
||||
webchannel_country_name text,
|
||||
webchannel_country_code text,
|
||||
webchannel_country_timezone text,
|
||||
webchannel_officialsite text,
|
||||
weight text);
|
||||
|
||||
ALTER TABLE dbo.seriesdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.seriesdata_row_id_seq OWNED BY dbo.seriesdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.tvnetworkdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.tvnetworkdata_row_id_seq'::regclass),
|
||||
networkid character varying(12),
|
||||
networkname character varying(255),
|
||||
country character varying(255),
|
||||
countrycode character varying(4),
|
||||
countrytimezone character varying(25));
|
||||
|
||||
ALTER TABLE dbo.tvnetworkdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.tvnetworkdata_row_id_seq OWNED BY dbo.tvnetworkdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.tvwebchanneldata (
|
||||
id integer NOT NULL DEFAULT nextval('dbo.tvwebchanneldata_id_seq'::regclass),
|
||||
webchannelname character varying(255),
|
||||
webchannelcountrycode character varying(4),
|
||||
webchannelcountryname character varying(255),
|
||||
webchannelcountrytimezone character varying(4));
|
||||
|
||||
ALTER TABLE dbo.tvwebchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.tvwebchanneldata_id_seq OWNED BY dbo.tvwebchanneldata.id;
|
||||
|
||||
CREATE TABLE dbo.webchanneldata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.webchanneldata_row_id_seq'::regclass),
|
||||
webchannelname character varying(255),
|
||||
webchannelcountrycode character varying(4),
|
||||
webchannelcountryname character varying(255),
|
||||
webchannelcountrytimezone character varying(4));
|
||||
|
||||
ALTER TABLE dbo.webchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.webchanneldata_row_id_seq OWNED BY dbo.webchanneldata.row_id;
|
||||
|
||||
CREATE TABLE updates.actordata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.actordata_row_id_seq'::regclass),
|
||||
actorid integer,
|
||||
actorname character varying(72),
|
||||
countryname character varying(144),
|
||||
countrytimezone character varying(72),
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(6),
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
url text,
|
||||
countrycode character varying(12));
|
||||
|
||||
ALTER TABLE updates.actordata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.actordata_row_id_seq OWNED BY updates.actordata.row_id;
|
||||
|
||||
CREATE TABLE updates.castdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.castdata_row_id_seq'::regclass),
|
||||
seriesid integer,
|
||||
characterid integer,
|
||||
actorid integer,
|
||||
charactername integer,
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
tvmazeilink text);
|
||||
|
||||
ALTER TABLE updates.castdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.castdata_row_id_seq OWNED BY updates.castdata.row_id;
|
||||
|
||||
CREATE TABLE updates.countrydata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.countrydata_row_id_seq'::regclass),
|
||||
country_name character varying(255),
|
||||
country_code character varying(255),
|
||||
country_timezone character varying(255));
|
||||
|
||||
ALTER TABLE updates.countrydata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.countrydata_row_id_seq OWNED BY updates.countrydata.row_id;
|
||||
|
||||
CREATE TABLE updates.crewdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.crewdata_row_id_seq'::regclass),
|
||||
crewid integer,
|
||||
crew_type character varying(128),
|
||||
name character varying(255),
|
||||
_links_self_href text,
|
||||
country_name text,
|
||||
country_code text,
|
||||
country_timezone text,
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(24),
|
||||
image_medium text,
|
||||
image_original text,
|
||||
updated text,
|
||||
url text);
|
||||
|
||||
ALTER TABLE updates.crewdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.crewdata_row_id_seq OWNED BY updates.crewdata.row_id;
|
||||
|
||||
CREATE TABLE updates.epdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.epdata_row_id_seq'::regclass),
|
||||
episodeid integer,
|
||||
seriesid integer,
|
||||
season integer,
|
||||
episode_number integer,
|
||||
episode_name text,
|
||||
airdate character varying(32),
|
||||
airtime character varying(32),
|
||||
summary text,
|
||||
airstamp character varying(32),
|
||||
runtime character varying(6),
|
||||
eplink text,
|
||||
image_medium text,
|
||||
url text,
|
||||
image_original text,
|
||||
episode_type text,
|
||||
rating_average text,
|
||||
_links_self_href text,
|
||||
_links_show_href text,
|
||||
_links_show_name text);
|
||||
|
||||
ALTER TABLE updates.epdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.epdata_row_id_seq OWNED BY updates.epdata.row_id;
|
||||
|
||||
CREATE TABLE updates.seriesdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.seriesdata_row_id_seq'::regclass),
|
||||
_links_previousepisode_href text,
|
||||
_links_previousepisode_name text,
|
||||
_links_nextepisode_href text,
|
||||
_links_nextepisode_name text,
|
||||
_links_self_href text,
|
||||
averageruntime text,
|
||||
dvdcountry text,
|
||||
series_name text,
|
||||
ended date,
|
||||
externals_imdb text,
|
||||
externals_thetvdb text,
|
||||
externals_tvrage text,
|
||||
genres text,
|
||||
seriesid text,
|
||||
image_medium text,
|
||||
image_original text,
|
||||
language_name text,
|
||||
network_id text,
|
||||
network_name text,
|
||||
officialsite text,
|
||||
network_officialsite text,
|
||||
network_country_code text,
|
||||
network_country_name text,
|
||||
network_country_timezone text,
|
||||
premiered text,
|
||||
rating_average text,
|
||||
runtime text,
|
||||
schedule_days text,
|
||||
schedule_time text,
|
||||
status text,
|
||||
summary text,
|
||||
series_type text,
|
||||
updated text,
|
||||
url text,
|
||||
webchannel_id integer,
|
||||
webchannel_name text,
|
||||
webchannel_country_name text,
|
||||
webchannel_country_code text,
|
||||
webchannel_country_timezone text,
|
||||
webchannel_officialsite text,
|
||||
weight text);
|
||||
|
||||
ALTER TABLE updates.seriesdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.seriesdata_row_id_seq OWNED BY updates.seriesdata.row_id;
|
||||
|
||||
CREATE TABLE updates.tvnetworkdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.tvnetworkdata_row_id_seq'::regclass),
|
||||
networkid character varying(12),
|
||||
networkname character varying(255),
|
||||
country character varying(255),
|
||||
countrycode character varying(4),
|
||||
countrytimezone character varying(25));
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvnetworkdata_row_id_seq OWNED BY updates.tvnetworkdata.row_id;
|
||||
|
||||
CREATE TABLE updates.tvupdates (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.tvupdates_row_id_seq'::regclass),
|
||||
seriesid integer,
|
||||
"timestamp" character varying(15));
|
||||
|
||||
ALTER TABLE updates.tvupdates OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvupdates_row_id_seq OWNED BY updates.tvupdates.row_id;
|
||||
|
||||
CREATE TABLE updates.tvwebchanneldata (
|
||||
row_id integer NOT NULL DEFAULT nextval('updates.tvwebchanneldata_id_seq'::regclass),
|
||||
name character varying(255),
|
||||
countryid character varying(255));
|
||||
|
||||
ALTER TABLE updates.tvwebchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvwebchanneldata_id_seq OWNED BY updates.tvwebchanneldata.row_id;
|
||||
|
||||
CREATE TABLE updates.webchanneldata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.webchanneldata_row_id_seq'::regclass),
|
||||
webchannel_name character varying(255),
|
||||
webchannel_country_code character varying(4),
|
||||
webchannel_country_name character varying(255),
|
||||
webchannelcountry_timezone character varying(4));
|
||||
|
||||
ALTER TABLE updates.webchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.webchanneldata_row_id_seq OWNED BY updates.webchanneldata.row_id;
|
||||
|
||||
ALTER TABLE dbo.actordata ADD CONSTRAINT actordata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.castdata ADD CONSTRAINT castdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.countrydata ADD CONSTRAINT countrydata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.epdata ADD CONSTRAINT epdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.seriesdata ADD CONSTRAINT seriesdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.tvnetworkdata ADD CONSTRAINT tvnetworkdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.tvwebchanneldata ADD CONSTRAINT tvwebchanneldata_pkey PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE dbo.webchanneldata ADD CONSTRAINT webchanneldata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.actordata ADD CONSTRAINT actordata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.actordata ADD CONSTRAINT actorid UNIQUE (actorid);
|
||||
|
||||
ALTER TABLE updates.castdata ADD CONSTRAINT castdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.castdata ADD CONSTRAINT series_actor_character_index UNIQUE (seriesid, characterid, actorid);
|
||||
|
||||
ALTER TABLE updates.countrydata ADD CONSTRAINT country_code_idx UNIQUE (country_code);
|
||||
|
||||
ALTER TABLE updates.countrydata ADD CONSTRAINT countrydata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.crewdata ADD CONSTRAINT crewdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.crewdata ADD CONSTRAINT crewid_crewid_idx UNIQUE (crewid);
|
||||
|
||||
ALTER TABLE updates.epdata ADD CONSTRAINT epdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.epdata ADD CONSTRAINT episodeie UNIQUE (episodeid);
|
||||
|
||||
ALTER TABLE updates.seriesdata ADD CONSTRAINT seriesdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.seriesdata ADD CONSTRAINT seriesid UNIQUE (seriesid);
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata ADD CONSTRAINT networkid UNIQUE (networkid);
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata ADD CONSTRAINT tvnetworkdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.tvupdates ADD CONSTRAINT tvupdates_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.tvwebchanneldata ADD CONSTRAINT tvwebchanneldata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.webchanneldata ADD CONSTRAINT webchanneldata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER SCHEMA updates OWNER TO postgres;
|
||||
@@ -0,0 +1,570 @@
|
||||
DROP SCHEMA dbo CASCADE;
|
||||
|
||||
DROP SCHEMA updates CASCADE;
|
||||
|
||||
CREATE SCHEMA dbo;
|
||||
|
||||
ALTER SCHEMA dbo OWNER TO postgres;
|
||||
|
||||
CREATE SCHEMA updates;
|
||||
|
||||
ALTER SCHEMA updates OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.actordata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.actordata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.castdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.castdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.countrydata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.countrydata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.crewdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.crewdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.epdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.epdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.epdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.epdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.seriesdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.seriesdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.tvnetworkdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.tvnetworkdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.tvwebchanneldata_id_seq
|
||||
AS integer START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
MAXVALUE 2147483647
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.tvwebchanneldata_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE dbo.webchanneldata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE dbo.webchanneldata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.actordata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.actordata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.castdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.castdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.countrydata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.countrydata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.crewdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.crewdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.seriesdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.seriesdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvnetworkdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvnetworkdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvupdates_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvupdates_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvwebchanneldata_id_seq
|
||||
AS integer START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
MAXVALUE 2147483647
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvwebchanneldata_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.webchanneldata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.webchanneldata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE TABLE dbo.actordata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.actordata_row_id_seq'::regclass),
|
||||
actorid integer,
|
||||
actorname character varying(72),
|
||||
countryname character varying(144),
|
||||
countrytimezone character varying(72),
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(6),
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
url text,
|
||||
countrycode character varying(12));
|
||||
|
||||
ALTER TABLE dbo.actordata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.actordata_row_id_seq OWNED BY dbo.actordata.row_id;
|
||||
|
||||
CREATE TABLE dbo.castdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.castdata_row_id_seq'::regclass),
|
||||
seriesid integer,
|
||||
characterid integer,
|
||||
actorid integer,
|
||||
charactername integer,
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
tvmazeilink text);
|
||||
|
||||
ALTER TABLE dbo.castdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.castdata_row_id_seq OWNED BY dbo.castdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.countrydata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.countrydata_row_id_seq'::regclass),
|
||||
country_name character varying(255),
|
||||
country_code character varying(255),
|
||||
country_timezone character varying(255));
|
||||
|
||||
ALTER TABLE dbo.countrydata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.countrydata_row_id_seq OWNED BY dbo.countrydata.row_id;
|
||||
|
||||
CREATE TABLE dbo.crewdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.crewdata_row_id_seq'::regclass),
|
||||
crewid integer,
|
||||
crew_type character varying(128),
|
||||
name character varying(255),
|
||||
_links_self_href text,
|
||||
country_name text,
|
||||
country_code text,
|
||||
country_timezone text,
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(24),
|
||||
image_medium text,
|
||||
image_original text,
|
||||
updated text,
|
||||
url text);
|
||||
|
||||
ALTER TABLE dbo.crewdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.crewdata_row_id_seq OWNED BY dbo.crewdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.epdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.epdata_row_id_seq'::regclass),
|
||||
episodeid integer,
|
||||
seriesid integer,
|
||||
season integer,
|
||||
episode_number integer,
|
||||
episode_name text,
|
||||
airdate character varying(32),
|
||||
airtime character varying(32),
|
||||
summary text,
|
||||
airstamp character varying(32),
|
||||
runtime character varying(6),
|
||||
eplink text,
|
||||
image_medium text,
|
||||
url text,
|
||||
image_original text,
|
||||
episode_type text,
|
||||
rating_average text,
|
||||
_links_self_href text,
|
||||
_links_show_href text,
|
||||
_links_show_name text);
|
||||
|
||||
ALTER TABLE dbo.epdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.epdata_row_id_seq OWNED BY dbo.epdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.seriesdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.seriesdata_row_id_seq'::regclass),
|
||||
_links_previousepisode_href text,
|
||||
_links_previousepisode_name text,
|
||||
_links_nextepisode_href text,
|
||||
_links_nextepisode_name text,
|
||||
_links_self_href text,
|
||||
averageruntime text,
|
||||
dvdcountry text,
|
||||
series_name text,
|
||||
ended date,
|
||||
externals_imdb text,
|
||||
externals_thetvdb text,
|
||||
externals_tvrage text,
|
||||
genres text,
|
||||
seriesid text,
|
||||
image_medium text,
|
||||
image_original text,
|
||||
language_name text,
|
||||
network_id text,
|
||||
network_name text,
|
||||
officialsite text,
|
||||
network_officialsite text,
|
||||
network_country_code text,
|
||||
network_country_name text,
|
||||
network_country_timezone text,
|
||||
premiered text,
|
||||
rating_average text,
|
||||
runtime text,
|
||||
schedule_days text,
|
||||
schedule_time text,
|
||||
status text,
|
||||
summary text,
|
||||
series_type text,
|
||||
updated text,
|
||||
url text,
|
||||
webchannel_id integer,
|
||||
webchannel_name text,
|
||||
webchannel_country_name text,
|
||||
webchannel_country_code text,
|
||||
webchannel_country_timezone text,
|
||||
webchannel_officialsite text,
|
||||
weight text);
|
||||
|
||||
ALTER TABLE dbo.seriesdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.seriesdata_row_id_seq OWNED BY dbo.seriesdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.tvnetworkdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.tvnetworkdata_row_id_seq'::regclass),
|
||||
networkid character varying(12),
|
||||
networkname character varying(255),
|
||||
country character varying(255),
|
||||
countrycode character varying(4),
|
||||
countrytimezone character varying(25));
|
||||
|
||||
ALTER TABLE dbo.tvnetworkdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.tvnetworkdata_row_id_seq OWNED BY dbo.tvnetworkdata.row_id;
|
||||
|
||||
CREATE TABLE dbo.tvwebchanneldata (
|
||||
id integer NOT NULL DEFAULT nextval('dbo.tvwebchanneldata_id_seq'::regclass),
|
||||
webchannelname character varying(255),
|
||||
webchannelcountrycode character varying(4),
|
||||
webchannelcountryname character varying(255),
|
||||
webchannelcountrytimezone character varying(4));
|
||||
|
||||
ALTER TABLE dbo.tvwebchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.tvwebchanneldata_id_seq OWNED BY dbo.tvwebchanneldata.id;
|
||||
|
||||
CREATE TABLE dbo.webchanneldata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('dbo.webchanneldata_row_id_seq'::regclass),
|
||||
webchannelname character varying(255),
|
||||
webchannelcountrycode character varying(4),
|
||||
webchannelcountryname character varying(255),
|
||||
webchannelcountrytimezone character varying(4));
|
||||
|
||||
ALTER TABLE dbo.webchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE dbo.webchanneldata_row_id_seq OWNED BY dbo.webchanneldata.row_id;
|
||||
|
||||
CREATE TABLE updates.actordata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.actordata_row_id_seq'::regclass),
|
||||
actorid integer,
|
||||
actorname character varying(72),
|
||||
countryname character varying(144),
|
||||
countrytimezone character varying(72),
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(6),
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
url text,
|
||||
countrycode character varying(12));
|
||||
|
||||
ALTER TABLE updates.actordata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.actordata_row_id_seq OWNED BY updates.actordata.row_id;
|
||||
|
||||
CREATE TABLE updates.castdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.castdata_row_id_seq'::regclass),
|
||||
seriesid integer,
|
||||
characterid integer,
|
||||
actorid integer,
|
||||
charactername integer,
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
tvmazeilink text);
|
||||
|
||||
ALTER TABLE updates.castdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.castdata_row_id_seq OWNED BY updates.castdata.row_id;
|
||||
|
||||
CREATE TABLE updates.countrydata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.countrydata_row_id_seq'::regclass),
|
||||
country_name character varying(255),
|
||||
country_code character varying(255),
|
||||
country_timezone character varying(255));
|
||||
|
||||
ALTER TABLE updates.countrydata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.countrydata_row_id_seq OWNED BY updates.countrydata.row_id;
|
||||
|
||||
CREATE TABLE updates.crewdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.crewdata_row_id_seq'::regclass),
|
||||
crewid integer,
|
||||
crew_type character varying(128),
|
||||
name character varying(255),
|
||||
_links_self_href text,
|
||||
country_name text,
|
||||
country_code text,
|
||||
country_timezone text,
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(24),
|
||||
image_medium text,
|
||||
image_original text,
|
||||
updated text,
|
||||
url text);
|
||||
|
||||
ALTER TABLE updates.crewdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.crewdata_row_id_seq OWNED BY updates.crewdata.row_id;
|
||||
|
||||
CREATE TABLE updates.epdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.epdata_row_id_seq'::regclass),
|
||||
episodeid integer,
|
||||
seriesid integer,
|
||||
season integer,
|
||||
episode_number integer,
|
||||
episode_name text,
|
||||
airdate character varying(32),
|
||||
airtime character varying(32),
|
||||
summary text,
|
||||
airstamp character varying(32),
|
||||
runtime character varying(6),
|
||||
eplink text,
|
||||
image_medium text,
|
||||
url text,
|
||||
image_original text,
|
||||
episode_type text,
|
||||
rating_average text,
|
||||
_links_self_href text,
|
||||
_links_show_href text,
|
||||
_links_show_name text);
|
||||
|
||||
ALTER TABLE updates.epdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.epdata_row_id_seq OWNED BY updates.epdata.row_id;
|
||||
|
||||
CREATE TABLE updates.seriesdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.seriesdata_row_id_seq'::regclass),
|
||||
_links_previousepisode_href text,
|
||||
_links_previousepisode_name text,
|
||||
_links_nextepisode_href text,
|
||||
_links_nextepisode_name text,
|
||||
_links_self_href text,
|
||||
averageruntime text,
|
||||
dvdcountry text,
|
||||
series_name text,
|
||||
ended date,
|
||||
externals_imdb text,
|
||||
externals_thetvdb text,
|
||||
externals_tvrage text,
|
||||
genres text,
|
||||
seriesid text,
|
||||
image_medium text,
|
||||
image_original text,
|
||||
language_name text,
|
||||
network_id text,
|
||||
network_name text,
|
||||
officialsite text,
|
||||
network_officialsite text,
|
||||
network_country_code text,
|
||||
network_country_name text,
|
||||
network_country_timezone text,
|
||||
premiered text,
|
||||
rating_average text,
|
||||
runtime text,
|
||||
schedule_days text,
|
||||
schedule_time text,
|
||||
status text,
|
||||
summary text,
|
||||
series_type text,
|
||||
updated text,
|
||||
url text,
|
||||
webchannel_id integer,
|
||||
webchannel_name text,
|
||||
webchannel_country_name text,
|
||||
webchannel_country_code text,
|
||||
webchannel_country_timezone text,
|
||||
webchannel_officialsite text,
|
||||
weight text);
|
||||
|
||||
ALTER TABLE updates.seriesdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.seriesdata_row_id_seq OWNED BY updates.seriesdata.row_id;
|
||||
|
||||
CREATE TABLE updates.tvnetworkdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.tvnetworkdata_row_id_seq'::regclass),
|
||||
networkid character varying(12),
|
||||
networkname character varying(255),
|
||||
country character varying(255),
|
||||
countrycode character varying(4),
|
||||
countrytimezone character varying(25));
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvnetworkdata_row_id_seq OWNED BY updates.tvnetworkdata.row_id;
|
||||
|
||||
CREATE TABLE updates.tvupdates (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.tvupdates_row_id_seq'::regclass),
|
||||
seriesid integer,
|
||||
"timestamp" character varying(15));
|
||||
|
||||
ALTER TABLE updates.tvupdates OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvupdates_row_id_seq OWNED BY updates.tvupdates.row_id;
|
||||
|
||||
CREATE TABLE updates.tvwebchanneldata (
|
||||
row_id integer NOT NULL DEFAULT nextval('updates.tvwebchanneldata_id_seq'::regclass),
|
||||
name character varying(255),
|
||||
countryid character varying(255));
|
||||
|
||||
ALTER TABLE updates.tvwebchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvwebchanneldata_id_seq OWNED BY updates.tvwebchanneldata.row_id;
|
||||
|
||||
CREATE TABLE updates.webchanneldata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.webchanneldata_row_id_seq'::regclass),
|
||||
webchannel_name character varying(255),
|
||||
webchannel_country_code character varying(4),
|
||||
webchannel_country_name character varying(255),
|
||||
webchannelcountry_timezone character varying(4));
|
||||
|
||||
ALTER TABLE updates.webchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.webchanneldata_row_id_seq OWNED BY updates.webchanneldata.row_id;
|
||||
|
||||
ALTER TABLE dbo.actordata ADD CONSTRAINT actordata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.castdata ADD CONSTRAINT castdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.countrydata ADD CONSTRAINT countrydata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.epdata ADD CONSTRAINT epdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.seriesdata ADD CONSTRAINT seriesdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.tvnetworkdata ADD CONSTRAINT tvnetworkdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE dbo.tvwebchanneldata ADD CONSTRAINT tvwebchanneldata_pkey PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE dbo.webchanneldata ADD CONSTRAINT webchanneldata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.actordata ADD CONSTRAINT actordata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.actordata ADD CONSTRAINT actorid UNIQUE (actorid);
|
||||
|
||||
ALTER TABLE updates.castdata ADD CONSTRAINT castdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.castdata ADD CONSTRAINT series_actor_character_index UNIQUE (seriesid, characterid, actorid);
|
||||
|
||||
ALTER TABLE updates.countrydata ADD CONSTRAINT country_code_idx UNIQUE (country_code);
|
||||
|
||||
ALTER TABLE updates.countrydata ADD CONSTRAINT countrydata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.crewdata ADD CONSTRAINT crewdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.crewdata ADD CONSTRAINT crewid_crewid_idx UNIQUE (crewid);
|
||||
|
||||
ALTER TABLE updates.epdata ADD CONSTRAINT epdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.epdata ADD CONSTRAINT episodeie UNIQUE (episodeid);
|
||||
|
||||
ALTER TABLE updates.seriesdata ADD CONSTRAINT seriesdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.seriesdata ADD CONSTRAINT seriesid UNIQUE (seriesid);
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata ADD CONSTRAINT networkid UNIQUE (networkid);
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata ADD CONSTRAINT tvnetworkdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.tvupdates ADD CONSTRAINT tvupdates_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.tvwebchanneldata ADD CONSTRAINT tvwebchanneldata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.webchanneldata ADD CONSTRAINT webchanneldata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER SCHEMA updates OWNER TO postgres;
|
||||
@@ -0,0 +1,299 @@
|
||||
DROP SCHEMA updates CASCADE;
|
||||
|
||||
CREATE SCHEMA updates;
|
||||
|
||||
ALTER SCHEMA updates OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.actordata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.actordata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.castdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.castdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.countrydata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.countrydata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.crewdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.crewdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.epdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.epdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.seriesdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.seriesdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvnetworkdata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvnetworkdata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvupdates_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvupdates_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.tvwebchanneldata_id_seq
|
||||
AS integer START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
MAXVALUE 2147483647
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.tvwebchanneldata_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE SEQUENCE updates.webchanneldata_row_id_seq START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
ALTER SEQUENCE updates.webchanneldata_row_id_seq OWNER TO postgres;
|
||||
|
||||
CREATE TABLE updates.actordata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.actordata_row_id_seq'::regclass),
|
||||
actorid integer,
|
||||
actorname character varying(72),
|
||||
countryname character varying(144),
|
||||
countrytimezone character varying(72),
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(6),
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
url text,
|
||||
countrycode character varying(12));
|
||||
|
||||
ALTER TABLE updates.actordata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.actordata_row_id_seq OWNED BY updates.actordata.row_id;
|
||||
|
||||
CREATE TABLE updates.castdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.castdata_row_id_seq'::regclass),
|
||||
seriesid integer,
|
||||
characterid integer,
|
||||
actorid integer,
|
||||
charactername integer,
|
||||
mediumimage text,
|
||||
originalimage text,
|
||||
apilink text,
|
||||
tvmazeilink text);
|
||||
|
||||
ALTER TABLE updates.castdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.castdata_row_id_seq OWNED BY updates.castdata.row_id;
|
||||
|
||||
CREATE TABLE updates.countrydata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.countrydata_row_id_seq'::regclass),
|
||||
country_name character varying(255),
|
||||
country_code character varying(255),
|
||||
country_timezone character varying(255));
|
||||
|
||||
ALTER TABLE updates.countrydata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.countrydata_row_id_seq OWNED BY updates.countrydata.row_id;
|
||||
|
||||
CREATE TABLE updates.crewdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.crewdata_row_id_seq'::regclass),
|
||||
crewid integer,
|
||||
crew_type character varying(128),
|
||||
name character varying(255),
|
||||
_links_self_href text,
|
||||
country_name text,
|
||||
country_code text,
|
||||
country_timezone text,
|
||||
birthday date,
|
||||
deathday date,
|
||||
gender character varying(24),
|
||||
image_medium text,
|
||||
image_original text,
|
||||
updated text,
|
||||
url text);
|
||||
ALTER TABLE updates.crewdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.crewdata_row_id_seq OWNED BY updates.crewdata.row_id;
|
||||
|
||||
CREATE TABLE updates.epdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.epdata_row_id_seq'::regclass),
|
||||
episodeid integer,
|
||||
seriesid integer,
|
||||
season integer,
|
||||
episode_number integer,
|
||||
episode_name text,
|
||||
airdate character varying(32),
|
||||
airtime character varying(32),
|
||||
summary text,
|
||||
airstamp character varying(32),
|
||||
runtime character varying(6),
|
||||
eplink text,
|
||||
image_medium text,
|
||||
url text,
|
||||
image_original text,
|
||||
episode_type text,
|
||||
rating_average text,
|
||||
_links_self_href text,
|
||||
_links_show_href text,
|
||||
_links_show_name text);
|
||||
|
||||
ALTER TABLE updates.epdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.epdata_row_id_seq OWNED BY updates.epdata.row_id;
|
||||
|
||||
CREATE TABLE updates.seriesdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.seriesdata_row_id_seq'::regclass),
|
||||
_links_previousepisode_href text,
|
||||
_links_previousepisode_name text,
|
||||
_links_nextepisode_href text,
|
||||
_links_nextepisode_name text,
|
||||
_links_self_href text,
|
||||
averageruntime text,
|
||||
dvdcountry text,
|
||||
series_name text,
|
||||
ended date,
|
||||
externals_imdb text,
|
||||
externals_thetvdb text,
|
||||
externals_tvrage text,
|
||||
genres text,
|
||||
seriesid text,
|
||||
image_medium text,
|
||||
image_original text,
|
||||
language_name text,
|
||||
network_id text,
|
||||
network_name text,
|
||||
officialsite text,
|
||||
network_officialsite text,
|
||||
network_country_code text,
|
||||
network_country_name text,
|
||||
network_country_timezone text,
|
||||
premiered text,
|
||||
rating_average text,
|
||||
runtime text,
|
||||
schedule_days text,
|
||||
schedule_time text,
|
||||
status text,
|
||||
summary text,
|
||||
series_type text,
|
||||
updated text,
|
||||
url text,
|
||||
webchannel_id integer,
|
||||
webchannel_name text,
|
||||
webchannel_country_name text,
|
||||
webchannel_country_code text,
|
||||
webchannel_country_timezone text,
|
||||
webchannel_officialsite text,
|
||||
weight text);
|
||||
|
||||
ALTER TABLE updates.seriesdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.seriesdata_row_id_seq OWNED BY updates.seriesdata.row_id;
|
||||
|
||||
CREATE TABLE updates.tvnetworkdata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.tvnetworkdata_row_id_seq'::regclass),
|
||||
networkid character varying(12),
|
||||
networkname character varying(255),
|
||||
country character varying(255),
|
||||
countrycode character varying(4),
|
||||
countrytimezone character varying(25));
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvnetworkdata_row_id_seq OWNED BY updates.tvnetworkdata.row_id;
|
||||
|
||||
CREATE TABLE updates.tvupdates (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.tvupdates_row_id_seq'::regclass),
|
||||
seriesid integer,
|
||||
"timestamp" character varying(15));
|
||||
|
||||
ALTER TABLE updates.tvupdates OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvupdates_row_id_seq OWNED BY updates.tvupdates.row_id;
|
||||
|
||||
CREATE TABLE updates.tvwebchanneldata (
|
||||
row_id integer NOT NULL DEFAULT nextval('updates.tvwebchanneldata_id_seq'::regclass),
|
||||
name character varying(255),
|
||||
countryid character varying(255));
|
||||
|
||||
ALTER TABLE updates.tvwebchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.tvwebchanneldata_id_seq OWNED BY updates.tvwebchanneldata.row_id;
|
||||
|
||||
CREATE TABLE updates.webchanneldata (
|
||||
row_id bigint NOT NULL DEFAULT nextval('updates.webchanneldata_row_id_seq'::regclass),
|
||||
webchannel_name character varying(255),
|
||||
webchannel_country_code character varying(4),
|
||||
webchannel_country_name character varying(255),
|
||||
webchannelcountry_timezone character varying(4));
|
||||
|
||||
ALTER TABLE updates.webchanneldata OWNER TO postgres;
|
||||
|
||||
ALTER SEQUENCE updates.webchanneldata_row_id_seq OWNED BY updates.webchanneldata.row_id;
|
||||
|
||||
ALTER TABLE updates.actordata ADD CONSTRAINT actordata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.actordata ADD CONSTRAINT actorid UNIQUE (actorid);
|
||||
|
||||
ALTER TABLE updates.castdata ADD CONSTRAINT castdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.castdata ADD CONSTRAINT series_actor_character_index UNIQUE (seriesid, characterid, actorid);
|
||||
|
||||
ALTER TABLE updates.countrydata ADD CONSTRAINT country_code_idx UNIQUE (country_code);
|
||||
|
||||
ALTER TABLE updates.countrydata ADD CONSTRAINT countrydata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.crewdata ADD CONSTRAINT crewdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.crewdata ADD CONSTRAINT seriesid_crewid_idx UNIQUE (crewid);
|
||||
|
||||
ALTER TABLE updates.epdata ADD CONSTRAINT epdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.epdata ADD CONSTRAINT episodeie UNIQUE (episodeid);
|
||||
|
||||
ALTER TABLE updates.seriesdata ADD CONSTRAINT seriesdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.seriesdata ADD CONSTRAINT seriesid UNIQUE (seriesid);
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata ADD CONSTRAINT networkid UNIQUE (networkid);
|
||||
|
||||
ALTER TABLE updates.tvnetworkdata ADD CONSTRAINT tvnetworkdata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.tvupdates ADD CONSTRAINT tvupdates_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.tvwebchanneldata ADD CONSTRAINT tvwebchanneldata_pkey PRIMARY KEY (row_id);
|
||||
|
||||
ALTER TABLE updates.webchanneldata ADD CONSTRAINT webchanneldata_pkey PRIMARY KEY (row_id);
|
||||
+605
@@ -0,0 +1,605 @@
|
||||
__author__ = "Wendell Jones"
|
||||
|
||||
import os
|
||||
import sqlalchemy
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
from sqlalchemy.orm import Session
|
||||
from db.Tables import Createtables, CreateTempTables, Tables as dbTables
|
||||
from db.mssql.Merger import Charactermerge as MSCharactermerge
|
||||
from db.mssql.Merger import Jsonmerge as MSJsonmerge
|
||||
from db.mssql.Merger import SQLGenerate as MSSQLGenerate
|
||||
from db.mssql.Merger import Episodemerge as MSEpisodemerge
|
||||
from db.pgsql.Merger import Charactermerge as PGCharactermerge
|
||||
from db.pgsql.Merger import Updatemerge as PGUpdatemerge
|
||||
from db.mssql.Merger import Jsonmerge as PGJsonmerge
|
||||
from db.pgsql.Merger import SQLGenerate as PGSQLGenerate
|
||||
from db.pgsql.Merger import Episodemerge as PGEpisodemerge
|
||||
import api.tvmaze.episodes
|
||||
import api.tvmaze.cast
|
||||
import api.tvmaze.series
|
||||
from pymongo import MongoClient
|
||||
from tqdm import tqdm
|
||||
|
||||
Createtables = Createtables
|
||||
CreateTempTables = CreateTempTables
|
||||
dbTables = dbTables
|
||||
|
||||
|
||||
class settype(object):
|
||||
|
||||
def __init__(self, dbtype, apitype, options):
|
||||
self.dbclass = {}
|
||||
self.dbengine = {}
|
||||
self.apiengine = {}
|
||||
self.load(dbtype)
|
||||
self.dbcreate(dbtype, options)
|
||||
self.setapi(apitype)
|
||||
self.get_data()
|
||||
|
||||
def load(self, dbtype):
|
||||
dbtype = dbtype.lower()
|
||||
if dbtype in ["pgsql", "mysql"]:
|
||||
Updatemerge = PGUpdatemerge
|
||||
Jsonmerge = PGJsonmerge
|
||||
Episodemerge = PGEpisodemerge
|
||||
Charactermerge = PGCharactermerge
|
||||
merger = PGSQLGenerate
|
||||
elif dbtype == "mssql":
|
||||
Jsonmerge = MSJsonmerge
|
||||
Charactermerge = MSCharactermerge
|
||||
merger = MSSQLGenerate
|
||||
Episodemerge = MSEpisodemerge
|
||||
|
||||
self.dbclass["jmerge"] = Jsonmerge()
|
||||
self.dbclass["cmerge"] = Charactermerge()
|
||||
self.dbclass["Createtables"] = Createtables
|
||||
self.dbclass["CreateTemptables"] = CreateTempTables
|
||||
self.dbclass["Tables"] = Createtables
|
||||
self.dbclass["merger"] = merger()
|
||||
|
||||
if dbtype == "pgsql":
|
||||
self.dbclass["Updatemerge"] = Updatemerge
|
||||
self.dbclass["Episodemerge"] = Episodemerge
|
||||
elif dbtype == "mssql":
|
||||
self.dbclass["Charactermerge"] = Charactermerge
|
||||
|
||||
def dbcreate(self, dbtype, options):
|
||||
updatesBase = automap_base()
|
||||
dboBase = automap_base()
|
||||
connection_string = None
|
||||
if dbtype.lower() == "mssql":
|
||||
connection_string = (
|
||||
"mssql+pymssql://"
|
||||
+ options["mssqlusername"]
|
||||
+ ":"
|
||||
+ options["mssqlpassword"]
|
||||
+ "@"
|
||||
+ options["hostname"]
|
||||
+ ":"
|
||||
+ options["mssqlport"]
|
||||
+ "/"
|
||||
+ options["dbname"]
|
||||
)
|
||||
elif dbtype.lower() == "pgsql":
|
||||
connection_string = (
|
||||
"postgresql+psycopg2://"
|
||||
+ options["pgsqlusername"]
|
||||
+ ":"
|
||||
+ options["pgsqlpassword"]
|
||||
+ "@"
|
||||
+ options["hostname"]
|
||||
+ ":"
|
||||
+ options["pgsqlport"]
|
||||
+ "/"
|
||||
+ options["dbname"]
|
||||
)
|
||||
elif dbtype.lower() == "mysql":
|
||||
connection_string = (
|
||||
"mysql+pymysql://"
|
||||
+ options["mysqlusername"]
|
||||
+ ":"
|
||||
+ options["mysqlpassword"]
|
||||
+ "@"
|
||||
+ options["hostname"]
|
||||
+ ":"
|
||||
+ options["mysqlport"]
|
||||
+ "/"
|
||||
+ options["dbname"]
|
||||
)
|
||||
engine = sqlalchemy.create_engine(
|
||||
connection_string, pool_size=20, max_overflow=20, pool_recycle=15
|
||||
)
|
||||
currentDir = os.path.dirname(os.path.abspath(__file__))
|
||||
currentDir = os.path.dirname(currentDir)
|
||||
ddl_file_path = f"{currentDir}/db/ddl/recreate_updates_schema.sql"
|
||||
with open(ddl_file_path, "r") as file:
|
||||
sql = file.read()
|
||||
file
|
||||
with engine.connect() as conn:
|
||||
with conn as cursor:
|
||||
cursor.execute(text(sql))
|
||||
# conn.commit()
|
||||
# with engine.connect() as conn:
|
||||
# conn.execute(text("CREATE SCHEMA IF NOT EXISTS updates"))
|
||||
# conn.execute(text("CREATE SCHEMA IF NOT EXISTS dbo"))
|
||||
# conn.commit()
|
||||
updatesBase.prepare(engine, reflect=True, schema="updates")
|
||||
dboBase.prepare(engine, reflect=True, schema="dbo")
|
||||
metadata = sqlalchemy.MetaData("updates")
|
||||
metadata.reflect(bind=engine)
|
||||
dboMetadata = sqlalchemy.MetaData("dbo")
|
||||
dboMetadata.reflect(bind=engine)
|
||||
session = Session(engine)
|
||||
self.dbengine["engine"] = engine
|
||||
self.dbengine["metadata"] = metadata
|
||||
self.dbengine["dbometadata"] = dboMetadata
|
||||
self.dbengine["updatesBase"] = updatesBase
|
||||
self.dbengine["dboBase"] = dboBase
|
||||
self.dbengine["session"] = session
|
||||
return self.dbengine
|
||||
|
||||
def setapi(self, apitype):
|
||||
if apitype.lower() == "tvmaze":
|
||||
self.apiengine["sprocess"] = api.tvmaze.series
|
||||
self.apiengine["cprocess"] = api.tvmaze.cast
|
||||
self.apiengine["eprocess"] = api.tvmaze.episodes
|
||||
return self.apiengine
|
||||
elif apitype.lower() == "thetvdb":
|
||||
pass
|
||||
|
||||
def reflect_tables(self, engine, Metadata):
|
||||
meta = MetaData()
|
||||
meta.reflect(bind=engine)
|
||||
return meta.tables
|
||||
|
||||
def get_data(self):
|
||||
return self.dbclass, self.dbengine, self.apiengine
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
class dbmongo(object):
|
||||
|
||||
global mgclient
|
||||
global mgseries
|
||||
global mgepisodes
|
||||
global mgactors
|
||||
global mgcharacters
|
||||
global mgcrew
|
||||
|
||||
def __init__(self, options):
|
||||
host = options["mghostname"]
|
||||
port = options["mgport"]
|
||||
print(f"Connecting to mongodb at {host}:{port}")
|
||||
try:
|
||||
self.connection_string = (
|
||||
f"mongodb://{options['mghostname']}:{options['mgport']}"
|
||||
)
|
||||
self.mgclient = MongoClient(self.connection_string)
|
||||
self.mgdb = self.mgclient[options["mgdbname"]]
|
||||
except BaseException as e:
|
||||
print(f"Unable to connect to mongodb.{e}\nExitting!")
|
||||
exit()
|
||||
else:
|
||||
self.mgseries = self.mgdb["series"]
|
||||
self.mgseries.create_index("id", unique=True)
|
||||
self.mgepisodes = self.mgdb["episodes"]
|
||||
self.mgepisodes.create_index("id", unique=True)
|
||||
self.mgactors = self.mgdb["actors"]
|
||||
self.mgactors.create_index("id", unique=True)
|
||||
self.mgcharacters = self.mgdb["characters"]
|
||||
self.mgcharacters.create_index("id", unique=True)
|
||||
self.mgcrew = self.mgdb["crew"]
|
||||
self.mgcrew.create_index("id", unique=True)
|
||||
print(
|
||||
f"Connection to mongodb at {options['mghostname']}:"
|
||||
f"{options['mgport']} successful."
|
||||
)
|
||||
|
||||
def load_json_file(self, cachefile, jget, lprint, seriesid, datatype):
|
||||
try:
|
||||
with open(cachefile, "r") as file:
|
||||
jsondata = file.read()
|
||||
datastring = jget.load(jsondata)
|
||||
data = jget.jconvert(datastring)
|
||||
return data
|
||||
except Exception:
|
||||
lprint.logprint(
|
||||
"info", f"Unable to open {datatype} file for {seriesid}"
|
||||
)
|
||||
# print(f'Unable to open {datatype} file for seriesid {seriesid}')
|
||||
return None
|
||||
|
||||
def process_series_data(
|
||||
self,
|
||||
seriesdata,
|
||||
jget,
|
||||
dbExec,
|
||||
dbengine,
|
||||
dboBase,
|
||||
lprint,
|
||||
countrydictionary,
|
||||
seriesid,
|
||||
):
|
||||
try:
|
||||
seriesresults, networkchannel, country, webchannel = (
|
||||
jget.processSeriesJson(seriesdata)
|
||||
)
|
||||
except Exception:
|
||||
lprint.logprint(
|
||||
"info", f"Unable to process series file for {seriesid}"
|
||||
)
|
||||
else:
|
||||
self.update_country_data(
|
||||
country,
|
||||
countrydictionary,
|
||||
dbExec,
|
||||
dbengine,
|
||||
dboBase,
|
||||
dbengine["dbometadata"],
|
||||
lprint,
|
||||
)
|
||||
self.update_network_data(
|
||||
networkchannel,
|
||||
countrydictionary,
|
||||
seriesresults,
|
||||
dbExec,
|
||||
dbengine,
|
||||
dboBase,
|
||||
lprint,
|
||||
)
|
||||
self.update_webchannel_data(
|
||||
webchannel,
|
||||
countrydictionary,
|
||||
seriesresults,
|
||||
dbExec,
|
||||
dbengine,
|
||||
dboBase,
|
||||
lprint,
|
||||
)
|
||||
self.insert_or_update_mongo(
|
||||
self.mgseries, seriesdata, "id"
|
||||
)
|
||||
|
||||
def process_cast_data(self, persondata, characterdata, seriesid, lprint):
|
||||
try:
|
||||
aupserts = [
|
||||
self.mgactors.update_many(
|
||||
{"id": x["id"]}, {"$setOnInsert": x}, upsert=True
|
||||
)
|
||||
for x in persondata
|
||||
]
|
||||
bupserts = [
|
||||
self.mgcharacters.update_many(
|
||||
{"id": x["id"]}, {"$setOnInsert": x}, upsert=True
|
||||
)
|
||||
for x in characterdata
|
||||
]
|
||||
except Exception as e:
|
||||
print(f"Skipping cast data.Reason: {str(e)}")
|
||||
else:
|
||||
[
|
||||
self.mgactors.update_many(
|
||||
{"id": x["id"]}, {"$setOnInsert": x}, upsert=True
|
||||
)
|
||||
for x in aupserts
|
||||
]
|
||||
[
|
||||
self.mgcharacters.insert_many(
|
||||
{"id": x["id"]}, {"$setOnInsert": x}, upsert=True
|
||||
)
|
||||
for x in bupserts
|
||||
]
|
||||
|
||||
def process_crew_data(self, crewdata, seriesid, jget, lprint):
|
||||
try:
|
||||
upserts = [
|
||||
self.mgcrew.update_many(
|
||||
{"id": x["id"]}, {"$setOnInsert": x}, upsert=True
|
||||
)
|
||||
for x in crewdata
|
||||
]
|
||||
except Exception as e:
|
||||
print(f"Skipping crew data.Reason: {str(e)}")
|
||||
else:
|
||||
[
|
||||
self.mgcrew.insert_many(
|
||||
{"id": x["id"]}, {"$setOnInsert": x}, upsert=True
|
||||
)
|
||||
for x in upserts
|
||||
]
|
||||
|
||||
def process_episode_data(self, episodedata, seriesid, lprint):
|
||||
try:
|
||||
upserts = [
|
||||
self.mgepisodes.update_many(
|
||||
{"id": x["id"]}, {"$setOnInsert": x}, upsert=True
|
||||
)
|
||||
for x in episodedata
|
||||
]
|
||||
except Exception as e:
|
||||
print(
|
||||
f"file does not contain the correct json. "
|
||||
f"Skipping. {str(e)}"
|
||||
)
|
||||
else:
|
||||
for episode in upserts:
|
||||
[
|
||||
self.mgepisodes.insert_many(
|
||||
{"id": x["id"]}, {"$setOnInsert": x}, upsert=True
|
||||
)
|
||||
for x in upserts
|
||||
]
|
||||
|
||||
def update_country_data(
|
||||
self, country, countrydictionary, dbExec, dbengine, dbBase,
|
||||
metadata, lprint
|
||||
):
|
||||
if len(country) > 0:
|
||||
try:
|
||||
selectquery = (
|
||||
f"select row_id, country_name from dbo.countrydata where "
|
||||
f"country_name = '{country['name'].replace("'", "''")}'"
|
||||
)
|
||||
countrylisting = dbExec.rawsql_select(
|
||||
dbengine["engine"], selectquery, lprint
|
||||
)
|
||||
for countryname in countrylisting:
|
||||
countrydictionary[countryname[1]] = countryname[0]
|
||||
except Exception as e:
|
||||
lprint.logprint(
|
||||
"info", (
|
||||
(
|
||||
f'Unable to process country data for '
|
||||
f'{country["name"]}. {e}'
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
if len(countrylisting) > 0:
|
||||
pass
|
||||
else:
|
||||
insert_sql = (
|
||||
(
|
||||
f"insert into dbo.countrydata "
|
||||
"(country_name, country_code, country_timezone) "
|
||||
f"values ('{country['name'].replace("'", "''")}', "
|
||||
f"'{country['code'].replace("'", "''")}', "
|
||||
f"'{country['timezone'].replace("'", "''")}')"
|
||||
)
|
||||
)
|
||||
dbExec.rawsql_insert(
|
||||
dbengine["engine"], insert_sql, lprint
|
||||
)
|
||||
# seriesresults['countryid'] = 'No Country'
|
||||
# return seriesresults['countryid']
|
||||
|
||||
def update_network_data(
|
||||
self,
|
||||
networkchannel,
|
||||
countrydictionary,
|
||||
seriesresults,
|
||||
dbExec,
|
||||
dbengine,
|
||||
dboBase,
|
||||
lprint,
|
||||
):
|
||||
if len(networkchannel) > 0:
|
||||
try:
|
||||
networkchannel["countryid"] = countrydictionary[
|
||||
networkchannel["country"]["name"]
|
||||
]
|
||||
seriesresults["networkid"] = networkchannel["id"]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def update_webchannel_data(
|
||||
self,
|
||||
webchannel,
|
||||
countrydictionary,
|
||||
seriesresults,
|
||||
dbExec,
|
||||
dbengine,
|
||||
dboBase,
|
||||
lprint,
|
||||
):
|
||||
if len(webchannel) > 0:
|
||||
try:
|
||||
webchannel["countryid"] = countrydictionary[
|
||||
webchannel["country"]["name"]
|
||||
]
|
||||
seriesresults["webchannelid"] = webchannel["id"]
|
||||
except Exception:
|
||||
pass
|
||||
seriesresults["seriesid"] = seriesresults["id"]
|
||||
del seriesresults["webchannel"]
|
||||
|
||||
def insert_or_update_mongo(self, collection, data, unique_key):
|
||||
try:
|
||||
collection.insert_one(data)
|
||||
except Exception:
|
||||
filter_query = {unique_key: data[unique_key]}
|
||||
new_values = {"$set": data}
|
||||
del new_values["$set"]["_id"]
|
||||
collection.update_one(filter_query, new_values)
|
||||
|
||||
def insert_or_update_many_mongo(self, collection, data, unique_key):
|
||||
try:
|
||||
collection.insert_many(data)
|
||||
except Exception:
|
||||
filter_query = {unique_key: data[unique_key]}
|
||||
new_values = {"$set": data}
|
||||
del new_values["$set"]["_id"]
|
||||
collection.update_one(filter_query, new_values)
|
||||
|
||||
def update_mongo(
|
||||
self,
|
||||
updateList,
|
||||
ROOTDIR,
|
||||
directories,
|
||||
jget,
|
||||
countrydictionary,
|
||||
dbExec,
|
||||
dbengine,
|
||||
dboBase,
|
||||
lprint,
|
||||
):
|
||||
print("Now inserting data into tables.")
|
||||
series_failed_count = 0
|
||||
episode_failed_count = 0
|
||||
cast_failed_count = 0
|
||||
crew_failed_count = 0
|
||||
processed_count = 0
|
||||
failed_file_count = 0
|
||||
|
||||
def process_data(
|
||||
file_path, data_type, process_method, failed_file_count, lprint
|
||||
):
|
||||
"""Helper function to load and process data."""
|
||||
data = self.load_json_file(
|
||||
file_path, jget, lprint, seriesid, data_type
|
||||
)
|
||||
if data:
|
||||
if "episode" in file_path:
|
||||
try:
|
||||
for item in data:
|
||||
item["seriesid"] = seriesid
|
||||
except Exception as e:
|
||||
lprint.logprint(
|
||||
"info", f"Unable to add {data_type} to data. {e}"
|
||||
)
|
||||
if "cast" in file_path:
|
||||
persondata = []
|
||||
characterdata = []
|
||||
for item in data:
|
||||
if "person" in item:
|
||||
persondata.append(item["person"])
|
||||
if "character" in item:
|
||||
characterdata.append(item["character"])
|
||||
try:
|
||||
for item in persondata:
|
||||
item["seriesid"] = seriesid
|
||||
for item in characterdata:
|
||||
item["seriesid"] = seriesid
|
||||
except Exception as e:
|
||||
lprint.logprint(
|
||||
"info", f"Unable to add {data_type} data. {e}"
|
||||
)
|
||||
|
||||
try:
|
||||
process_method(
|
||||
persondata, characterdata, seriesid, lprint
|
||||
)
|
||||
failed_file_count = "N/A"
|
||||
return failed_file_count
|
||||
except Exception as e:
|
||||
failed_file_count = 1
|
||||
lprint.logprint(
|
||||
"info",
|
||||
f"Unable to process {data_type} data. {e}"
|
||||
)
|
||||
return failed_file_count
|
||||
if "crew" in file_path:
|
||||
try:
|
||||
crewdata = []
|
||||
except Exception as e:
|
||||
lprint.logprint(
|
||||
"info",
|
||||
f"Unable to add {data_type} data. {e}"
|
||||
)
|
||||
else:
|
||||
for item in data:
|
||||
item["seriesid"] = seriesid
|
||||
if "person" in item:
|
||||
crewdata.append(item["person"])
|
||||
try:
|
||||
process_method(crewdata, seriesid, jget, lprint)
|
||||
failed_file_count = "N/A"
|
||||
return failed_file_count
|
||||
except Exception as e:
|
||||
failed_file_count = 1
|
||||
lprint.logprint(
|
||||
"info",
|
||||
f"Unable to process {data_type} data.{e}"
|
||||
)
|
||||
return failed_file_count
|
||||
|
||||
for series in tqdm(
|
||||
range(len(updateList)), desc="Update MongoDB", unit="series"
|
||||
):
|
||||
seriesid = updateList[series]
|
||||
seriescachefile = f'{directories["SERIESDIR"]}{seriesid}.json'
|
||||
episodecachefile = f'{directories["EPISODEDIR"]}{seriesid}.json'
|
||||
castcachefile = f'{directories["CASTDIR"]}{seriesid}.json'
|
||||
crewcachefile = f'{directories["CREWDIR"]}{seriesid}.json'
|
||||
|
||||
# Process series data
|
||||
seriesdata = self.load_json_file(
|
||||
seriescachefile, jget, lprint, seriesid, "series"
|
||||
)
|
||||
if seriesdata:
|
||||
try:
|
||||
self.process_series_data(
|
||||
seriesdata,
|
||||
jget,
|
||||
dbExec,
|
||||
dbengine,
|
||||
dboBase,
|
||||
lprint,
|
||||
countrydictionary,
|
||||
seriesid,
|
||||
)
|
||||
self.insert_or_update_mongo(
|
||||
self.mgseries, seriesdata, "id"
|
||||
)
|
||||
except Exception as e:
|
||||
series_failed_count += 1
|
||||
lprint.logprint(
|
||||
"info",
|
||||
(
|
||||
f"Unable to process series data for seriesid "
|
||||
f"{seriesid}. {e}"
|
||||
),
|
||||
)
|
||||
else:
|
||||
processed_count += 1
|
||||
|
||||
# Process episode, cast, and crew data using the helper function
|
||||
fcount = process_data(
|
||||
episodecachefile,
|
||||
"episode",
|
||||
self.process_episode_data,
|
||||
failed_file_count,
|
||||
lprint,
|
||||
)
|
||||
if isinstance(fcount, int):
|
||||
episode_failed_count = episode_failed_count + fcount
|
||||
fcount = process_data(
|
||||
castcachefile, "cast", self.process_cast_data,
|
||||
failed_file_count, lprint
|
||||
)
|
||||
if isinstance(fcount, int):
|
||||
cast_failed_count = cast_failed_count + fcount
|
||||
try:
|
||||
fcount = process_data(
|
||||
crewcachefile, "crew", self.process_crew_data,
|
||||
failed_file_count, lprint
|
||||
)
|
||||
except Exception:
|
||||
crew_failed_count = crew_failed_count + 1
|
||||
else:
|
||||
if isinstance(fcount, int):
|
||||
crew_failed_count = crew_failed_count + fcount
|
||||
processed_count += 1
|
||||
|
||||
print(f"Processing complete. {processed_count} series processed.")
|
||||
print(f"Failed to load {series_failed_count} series files.")
|
||||
print(f"Failed to load {episode_failed_count} episode files.")
|
||||
print(f"Failed to load {crew_failed_count} crew files.")
|
||||
print(f"Failed to load {cast_failed_count} cast files.")
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
@@ -0,0 +1,327 @@
|
||||
from sqlalchemy import text
|
||||
|
||||
class SQLGenerate():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def merge_updates(self):
|
||||
updatesql = text('''
|
||||
MERGE updates.tvupdatedata
|
||||
USING updates.tvupdates
|
||||
ON updates.tvupdatedata.seriesid = updates.tvupdates.seriesid
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET updates.tvupdatedata.seriesid = updates.tvupdates.seriesid,updates.tvupdatedata.timestamp = updates.tvupdates.timestamp
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (seriesid, timestamp)
|
||||
VALUES (updates.tvupdates.seriesid, updates.tvupdates.timestamp);
|
||||
''')
|
||||
return(updatesql)
|
||||
|
||||
def merge_series(self):
|
||||
seriessql = text('''
|
||||
MERGE dbo.seriesdata
|
||||
USING updates.newseriesdata ON
|
||||
dbo.seriesdata.seriesid = updates.newseriesdata.seriesid
|
||||
WHEN MATCHED THEN UPDATE
|
||||
SET
|
||||
dbo.seriesdata.seriesid = updates.newseriesdata.seriesid,
|
||||
dbo.seriesdata.thetvdb = updates.newseriesdata.thetvdb,
|
||||
dbo.seriesdata.tvrage = updates.newseriesdata.tvrage,
|
||||
dbo.seriesdata.imdb = updates.newseriesdata.imdb,
|
||||
dbo.seriesdata.[language] = updates.newseriesdata.[language],
|
||||
dbo.seriesdata.genres = updates.newseriesdata.genres,
|
||||
dbo.seriesdata.name = updates.newseriesdata.name,
|
||||
dbo.seriesdata.status = updates.newseriesdata.status,
|
||||
dbo.seriesdata.premiered = updates.newseriesdata.premiered,
|
||||
dbo.seriesdata.days = updates.newseriesdata.days,
|
||||
dbo.seriesdata.[time] = updates.newseriesdata.[time],
|
||||
dbo.seriesdata.runtime = updates.newseriesdata.runtime,
|
||||
dbo.seriesdata.rating = updates.newseriesdata.rating,
|
||||
dbo.seriesdata.[type] = updates.newseriesdata.[type],
|
||||
dbo.seriesdata.summary = updates.newseriesdata.summary,
|
||||
dbo.seriesdata.medium = updates.newseriesdata.medium,
|
||||
dbo.seriesdata.original = updates.newseriesdata.original,
|
||||
dbo.seriesdata.[weight] = updates.newseriesdata.[weight],
|
||||
dbo.seriesdata.networkid = updates.newseriesdata.networkid,
|
||||
dbo.seriesdata.webchannelid = updates.newseriesdata.webchannelid,
|
||||
dbo.seriesdata.officialsite = updates.newseriesdata.officalsite,
|
||||
dbo.seriesdata.url = updates.newseriesdata.url,
|
||||
dbo.seriesdata.serieslink = updates.newseriesdata.serieslink,
|
||||
dbo.seriesdata.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN INSERT
|
||||
(seriesid,
|
||||
thetvdb,
|
||||
tvrage,
|
||||
imdb,
|
||||
[language],
|
||||
genres,
|
||||
name,
|
||||
status,
|
||||
premiered,
|
||||
days,
|
||||
[time],
|
||||
runtime,
|
||||
rating,
|
||||
[type],
|
||||
summary,
|
||||
medium,
|
||||
original,
|
||||
weight,
|
||||
networkid,
|
||||
webchannelid,
|
||||
officialsite,
|
||||
url,
|
||||
serieslink,
|
||||
created_on)
|
||||
VALUES (updates.newseriesdata.seriesid,
|
||||
updates.newseriesdata.thetvdb,
|
||||
updates.newseriesdata.tvrage,
|
||||
updates.newseriesdata.imdb,
|
||||
updates.newseriesdata.[language],
|
||||
updates.newseriesdata.genres,
|
||||
updates.newseriesdata.name,
|
||||
updates.newseriesdata.status,
|
||||
updates.newseriesdata.premiered,
|
||||
updates.newseriesdata.days,
|
||||
updates.newseriesdata.[time],
|
||||
updates.newseriesdata.runtime,
|
||||
updates.newseriesdata.rating,
|
||||
updates.newseriesdata.[type],
|
||||
updates.newseriesdata.summary,
|
||||
updates.newseriesdata.medium,
|
||||
updates.newseriesdata.original,
|
||||
updates.newseriesdata.weight,
|
||||
updates.newseriesdata.networkid,
|
||||
updates.newseriesdata.webchannelid,
|
||||
updates.newseriesdata.officalsite,
|
||||
updates.newseriesdata.url,
|
||||
updates.newseriesdata.serieslink,
|
||||
GETDATE());
|
||||
''')
|
||||
return(seriessql)
|
||||
|
||||
def merge_episodes(self):
|
||||
episodesql = text('''
|
||||
MERGE dbo.epdata
|
||||
USING updates.newepdata ON
|
||||
dbo.epdata.episodeid = updates.newepdata.episodeid
|
||||
WHEN MATCHED THEN UPDATE
|
||||
SET
|
||||
dbo.epdata.episodeid = updates.newepdata.episodeid,
|
||||
dbo.epdata.seriesid = updates.newepdata.seriesid,
|
||||
dbo.epdata.season = updates.newepdata.season,
|
||||
dbo.epdata.episodenumber = updates.newepdata.episodenumber,
|
||||
dbo.epdata.episodename = updates.newepdata.episodename,
|
||||
dbo.epdata.airdate = updates.newepdata.airdate,
|
||||
dbo.epdata.airtime = updates.newepdata.airtime,
|
||||
dbo.epdata.episodesummary = updates.newepdata.episodesummary,
|
||||
dbo.epdata.airstamp = updates.newepdata.airstamp,
|
||||
dbo.epdata.runtime = updates.newepdata.runtime,
|
||||
dbo.epdata.eplink = updates.newepdata.eplink,
|
||||
dbo.epdata.mediumimage = updates.newepdata.mediumimage,
|
||||
dbo.epdata.originalimage = updates.newepdata.originalimage,
|
||||
dbo.epdata.[url] = updates.newepdata.[url],
|
||||
dbo.epdata.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN INSERT
|
||||
(episodeid,
|
||||
seriesid,
|
||||
season,
|
||||
episodenumber,
|
||||
episodename,
|
||||
airdate,
|
||||
airtime,
|
||||
episodesummary,
|
||||
airstamp,
|
||||
runtime,
|
||||
eplink,
|
||||
mediumimage,
|
||||
originalimage,
|
||||
[url],
|
||||
created_on)
|
||||
VALUES (updates.newepdata.episodeid,
|
||||
updates.newepdata.seriesid,
|
||||
updates.newepdata.season,
|
||||
updates.newepdata.episodenumber,
|
||||
updates.newepdata.episodename,
|
||||
updates.newepdata.airdate,
|
||||
updates.newepdata.airtime,
|
||||
updates.newepdata.episodesummary,
|
||||
updates.newepdata.airstamp,
|
||||
updates.newepdata.runtime,
|
||||
updates.newepdata.eplink,
|
||||
updates.newepdata.mediumimage,
|
||||
updates.newepdata.originalimage,
|
||||
updates.newepdata.[url],
|
||||
GETDATE());
|
||||
''')
|
||||
return(episodesql)
|
||||
|
||||
def merge_cast(self):
|
||||
castsql = text('''
|
||||
MERGE castdata as N
|
||||
USING updates.newcastdata as O
|
||||
ON N.seriesid = O.seriesid and N.characterid = O.characterid and N.actorid = O.actorid
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET N.seriesid = O.seriesid, N.characterid = O.characterid,N.actorid = O.actorid,N.charactername = O.charactername,N.mediumimage = O.mediumimage,N.originalimage = O.originalimage,N.apilink = O.apilink,N.tvmazelink = O.tvmazelink, N.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (seriesid,characterid,actorid,charactername,mediumimage,originalimage,apilink,tvmazelink, created_on)
|
||||
VALUES
|
||||
(O.seriesid,O.characterid,O.actorid,O.charactername,O.mediumimage,O.originalimage,O.apilink,O.tvmazelink, GETDATE());
|
||||
''')
|
||||
return(castsql)
|
||||
|
||||
def merge_actors(self):
|
||||
actorsql = text('''
|
||||
MERGE actors as N
|
||||
USING updates.newactordata as O
|
||||
ON N.actorid = O.actorid and N.actorname = O.actorname
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET N.actorid = O.actorid, N.actorname = O.actorname, N.countryname = O.countryname, N.countrytimezone = O.countrytimezone, N.birthday = O.birthday, N.deathday = O.deathday, N.gender = O.gender, N.mediumimage = O.mediumimage, N.originalimage = O.originalimage, N.apilink = O.apilink, N.url = O.url, N.countrycode = O.countrycode, N.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (actorid,actorname,countryname,countrytimezone,birthday,deathday,gender,mediumimage,originalimage,apilink,url,countrycode,created_on)
|
||||
VALUES
|
||||
(O.actorid,O.actorname,O.countryname,O.countrytimezone,O.birthday,O.deathday,O.gender,O.mediumimage,O.originalimage,O.apilink,O.url,O.countrycode, GETDATE());
|
||||
''')
|
||||
return(actorsql)
|
||||
|
||||
def merge_crew(self):
|
||||
crewsql = text('''
|
||||
MERGE dbo.crewdata as N
|
||||
USING updates.newcrewdata as O ON
|
||||
N.[type] = O.[type]
|
||||
and N.seriesid = O.seriesid
|
||||
and N.crewid = O.crewid
|
||||
WHEN MATCHED THEN UPDATE
|
||||
SET
|
||||
N.seriesid = O.seriesid,
|
||||
N.crewid = O.crewid,
|
||||
N.countryid = O.countryid,
|
||||
N.type = O.type,
|
||||
N.name = O.name,
|
||||
N.medium = O.medium,
|
||||
N.original = O.original,
|
||||
N.apilink = O.apilink,
|
||||
N.gender = O.gender,
|
||||
N.birthday = O.birthday,
|
||||
N.deathday = O.deathday,
|
||||
N.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN INSERT
|
||||
(seriesid,
|
||||
crewid,
|
||||
countryid,
|
||||
type,
|
||||
name,
|
||||
medium,
|
||||
original,
|
||||
apilink,
|
||||
gender,
|
||||
birthday,
|
||||
deathday,
|
||||
created_on)
|
||||
VALUES (O.seriesid,
|
||||
O.crewid,
|
||||
O.countryid,
|
||||
O.type,
|
||||
O.name,
|
||||
O.medium,
|
||||
O.original,
|
||||
O.apilink,
|
||||
O.gender,
|
||||
O.birthday,
|
||||
O.deathday,
|
||||
GETDATE());
|
||||
''')
|
||||
return(crewsql)
|
||||
|
||||
def merge_country(self):
|
||||
countrysql = text('''
|
||||
MERGE countrydata
|
||||
USING updates.newcountrydata
|
||||
ON countrydata.id = updates.newcountrydata.id
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET countrydata.name = updates.newcountrydata.name, countrydata.code = updates.newcountrydata.code, countrydata.timezone = updates.newcountrydata.timezone, countrydata.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (name, code, timezone, created_on)
|
||||
VALUES
|
||||
(updates.newcountrydata.name,updates.newcountrydata.code,updates.newcountrydata.timezone, GETDATE());
|
||||
''')
|
||||
return(countrysql)
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class Charactermerge():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class Episodemerge():
|
||||
def __init_(self):
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class Jsonmerge():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def merge(self, engine):
|
||||
seriessql = text('''BEGIN TRANSACTION;
|
||||
MERGE dbo.seriesjson as N
|
||||
USING updates.seriesjsonnewvals as O
|
||||
ON N.seriesid = O.seriesid and N.jdata = O.jdata
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET N.seriesid = O.seriesid, N.jdata = O.jdata, N.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (seriesid, jdata, created_on)
|
||||
VALUES
|
||||
(O.seriesid, O.jdata, GETDATE());
|
||||
COMMIT;
|
||||
''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(seriessql)
|
||||
#engine.commit()
|
||||
|
||||
episodesql = text('''BEGIN TRANSACTION;
|
||||
MERGE updates.tvmaze_episodejson as N
|
||||
USING updates.episodejsonnewvals as O
|
||||
ON N.seriesid = O.seriesid
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET N.seriesid = O.seriesid, N.jdata = O.jdata, N.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (seriesid, jdata, created_on)
|
||||
VALUES
|
||||
(O.seriesid, O.jdata, GETDATE());
|
||||
SELECT * FROM updates.tvmaze_episodejson;COMMIT;
|
||||
''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(episodesql)
|
||||
#engine.commit()
|
||||
|
||||
charactersql = text('''BEGIN TRANSACTION;
|
||||
MERGE updates.tvmaze_characterjson as N
|
||||
USING updates.characterjsonnewvals as O
|
||||
ON N.seriesid = O.seriesid
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET N.seriesid = O.seriesid, N.jdata = O.jdata, N.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (seriesid, jdata, created_on)
|
||||
VALUES
|
||||
(O.seriesid, O.jdata, GETDATE());
|
||||
SELECT * FROM updates.tvmaze_characterjson;COMMIT;
|
||||
''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(charactersql)
|
||||
#engine.commit()
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,376 @@
|
||||
import sqlalchemy
|
||||
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, Sequence, text, UniqueConstraint
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.schema import MetaData
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.types import *
|
||||
|
||||
class Tables():
|
||||
def __init__(self):
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global metadata
|
||||
global engine
|
||||
global session
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global tvupdates
|
||||
global newseriesdata
|
||||
global actorlinks
|
||||
global tablelist
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
class Createtables():
|
||||
|
||||
def __init__(self, session, metadata, engine, tablelist):
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
session.commit()
|
||||
#self.send(tablelist)
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
newseriesdata = Table('newseriesdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newseriesdata_id_seq'), primary_key = True),
|
||||
Column('seriesid',INTEGER, unique=True),
|
||||
Column('tvdbid', String(25)),
|
||||
Column('tvrageid', String(25)),
|
||||
Column('imdbid', String(25)),
|
||||
Column('serieslanguage', String(25)),
|
||||
Column('genres', String(75)),
|
||||
Column('seriesname', String(150)),
|
||||
Column('seriesstatus', String(25)),
|
||||
Column('premiered', String(25)),
|
||||
Column('airdays', String(72)),
|
||||
Column('airtime', String(25)),
|
||||
Column('runtime', String(25)),
|
||||
Column('rating', String(25)),
|
||||
Column('showtype',TEXT),
|
||||
Column('overview',TEXT),
|
||||
Column('mediumimage',TEXT),
|
||||
Column('originalimage',TEXT),
|
||||
Column('weight',INTEGER),
|
||||
Column('networkid', String(25)),
|
||||
Column('webchannelid', String(25)),
|
||||
Column('officialsite',TEXT),
|
||||
Column('showurl',TEXT),
|
||||
Column('apilink',TEXT),
|
||||
schema = "updates")
|
||||
tablelist.append(newseriesdata)
|
||||
newactordata = Table('newactordata', metadata,
|
||||
Column('id', BIGINT, Sequence('newactordata_id_seq'), primary_key = True),
|
||||
Column('actorid', INTEGER, unique=True),
|
||||
Column('actorname', VARCHAR(72)),
|
||||
Column('countryname', VARCHAR(144)),
|
||||
Column('countrytimezone', VARCHAR(72)),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(6)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('countrycode', VARCHAR(12)),
|
||||
schema = "updates")
|
||||
tablelist.append(newactordata)
|
||||
newepdata = Table('newepdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newepdata_id_seq'), primary_key = True),
|
||||
Column('episodeid', INTEGER),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('season', INTEGER),
|
||||
Column('episodenumber', INTEGER),
|
||||
Column('episodename', TEXT),
|
||||
Column('airdate', VARCHAR(32)),
|
||||
Column('airtime', VARCHAR(32)),
|
||||
Column('episodesummary', TEXT),
|
||||
Column('airstamp', VARCHAR(32)),
|
||||
Column('runtime', VARCHAR(6)),
|
||||
Column('eplink', TEXT),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
schema = "updates")
|
||||
tablelist.append(newepdata)
|
||||
newcastdata = Table('newcastdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newcastdata_id_seq'), primary_key = True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('characterid', INTEGER),
|
||||
Column('actorid', INTEGER),
|
||||
Column('charactername', VARCHAR(250)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('tvmazelink', TEXT),
|
||||
schema = "updates")
|
||||
tablelist.append(newcastdata)
|
||||
tvnetworks = Table('tvnetworkdata', metadata,
|
||||
Column('id', BIGINT, Sequence('network_id_seq'), primary_key = True),
|
||||
Column('networkid', String(12)),
|
||||
Column('networkname', String(255)),
|
||||
Column('country', String(255)),
|
||||
Column('countrycode', String(4)),
|
||||
Column('countrytimezone', String(25)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvnetworks)
|
||||
tvwebchannels = Table('tvwebchanneldata', metadata,
|
||||
Column('id', BIGINT, Sequence('webchannel_id_seq'), primary_key = True),
|
||||
Column('webchannelname', String(255)),
|
||||
Column('webchannelcountrycode', String(4)),
|
||||
Column('webchannelcountryname', String(255)),
|
||||
Column('webchannelcountrytimezone', String(4)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvwebchannels)
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
print('Creating Temporary Data Tables')
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
for table in tablelist:
|
||||
try:
|
||||
#print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
class Temptables():
|
||||
|
||||
def __init__(self, session, metadata, engine, tablelist):
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
#session.commit()
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
tvnetworknewvals = Table('tvnetworknewvals', metadata,
|
||||
Column('id', BIGINT, Sequence('network_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvnetworknewvals)
|
||||
tvwebchannelnewvals = Table('tvwebchannelnewvals', metadata,
|
||||
Column('id', BIGINT, Sequence('webchannel_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(4)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvwebchannelnewvals)
|
||||
tvupdates = Table('tvupdates', metadata,
|
||||
Column('seriesid', BIGINT, primary_key = True),
|
||||
Column('timestamp', VARCHAR(15)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvupdates)
|
||||
tvupdatedata = Table('tvupdatedata', metadata,
|
||||
Column('seriesid', BIGINT, primary_key = True),
|
||||
Column('timestamp', VARCHAR(15)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvupdatedata)
|
||||
newactorlinks = Table('newactorlinks', metadata,
|
||||
Column('id', BIGINT, Sequence('tempepisodejson_id_seq'), primary_key = True),
|
||||
Column('actorid', INTEGER),
|
||||
Column('characterid', INTEGER),
|
||||
schema = "updates")
|
||||
tablelist.append(newactorlinks)
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
tablelist.remove(tablelist[6])
|
||||
print('Creating Temporary JSON Tables')
|
||||
try:
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
except sqlalchemy.exc.ProgrammingError as pe:
|
||||
pass
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
for table in tablelist:
|
||||
if 'tvupdatedata' in table.description:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
#print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
#session.commit()
|
||||
|
||||
class CreateTempTables():
|
||||
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global metadata
|
||||
global engine
|
||||
global session
|
||||
|
||||
global tablelist
|
||||
|
||||
def __init__(self, session, metadata, engine, tablelist):
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
session.commit()
|
||||
#self.send(tablelist)
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
newseriesdata = Table('newseriesdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newseriesdata_id_seq'), primary_key = True),
|
||||
Column('seriesid',INTEGER, unique=True),
|
||||
Column('thetvdb', String(25)),
|
||||
Column('tvrage', String(25)),
|
||||
Column('imdb', String(25)),
|
||||
Column('language', String(25)),
|
||||
Column('genres', String(75)),
|
||||
Column('name', String(150)),
|
||||
Column('status', String(25)),
|
||||
Column('premiered', String(25)),
|
||||
Column('days', String(72)),
|
||||
Column('time', String(25)),
|
||||
Column('runtime', String(25)),
|
||||
Column('rating', String(25)),
|
||||
Column('type',TEXT),
|
||||
Column('summary',TEXT),
|
||||
Column('medium',TEXT),
|
||||
Column('original',TEXT),
|
||||
Column('weight',INTEGER),
|
||||
Column('networkid', String(25)),
|
||||
Column('webchannelid', String(25)),
|
||||
Column('officialsite',TEXT),
|
||||
Column('url',TEXT),
|
||||
Column('serieslink',TEXT),
|
||||
schema="updates")
|
||||
tablelist.append(newseriesdata)
|
||||
newactordata = Table('newactordata', metadata,
|
||||
Column('id', BIGINT, Sequence('newactordata_id_seq'), primary_key = True),
|
||||
Column('actorid', INTEGER, unique=True),
|
||||
Column('actorname', VARCHAR(72)),
|
||||
Column('countryname', VARCHAR(36)),
|
||||
Column('countrytimezone', VARCHAR(72)),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(6)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('countrycode', VARCHAR(12)),
|
||||
schema="updates")
|
||||
tablelist.append(newactordata)
|
||||
newepdata = Table('newepdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newepdata_id_seq'), primary_key = True),
|
||||
Column('episodeid', INTEGER),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('season', INTEGER),
|
||||
Column('episodenumber', INTEGER),
|
||||
Column('episodename', TEXT),
|
||||
Column('airdate', VARCHAR(32)),
|
||||
Column('airtime', VARCHAR(32)),
|
||||
Column('episodesummary', TEXT),
|
||||
Column('airstamp', VARCHAR(32)),
|
||||
Column('runtime', VARCHAR(6)),
|
||||
Column('eplink', TEXT),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
schema="updates")
|
||||
tablelist.append(newepdata)
|
||||
newcastdata = Table('newcastdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newcastdata_id_seq'), primary_key = True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('characterid', VARCHAR(24)),
|
||||
Column('actorid', VARCHAR(24)),
|
||||
Column('url', TEXT),
|
||||
Column('charactername', VARCHAR(128)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('tvmazelink', TEXT),
|
||||
Column('self', CHAR),
|
||||
Column('voice', CHAR),
|
||||
schema="updates")
|
||||
tablelist.append(newcastdata)
|
||||
newcrewdata = Table('newcrewdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newcrewdata_id_seq'), primary_key = True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('crewid', VARCHAR(128)),
|
||||
Column('type', VARCHAR(128)),
|
||||
Column('url', TEXT),
|
||||
Column('name', VARCHAR(256)),
|
||||
Column('countryid', INTEGER),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(24)),
|
||||
Column('medium', TEXT),
|
||||
Column('original', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
UniqueConstraint('seriesid', 'crewid', 'type', name='crew_unique'),
|
||||
schema="updates")
|
||||
tablelist.append(newcrewdata)
|
||||
tvnetworks = Table('tvnetworkdata', metadata,
|
||||
Column('id', BIGINT, Sequence('network_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvnetworks)
|
||||
tvwebchannels = Table('tvwebchanneldata', metadata,
|
||||
Column('id', BIGINT, Sequence('webchannel_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvwebchannels)
|
||||
countries = Table('newcountrydata', metadata,
|
||||
Column('id', BIGINT, Sequence('country_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('code', String(255)),
|
||||
Column('timezone', String(255)),
|
||||
UniqueConstraint('name', 'timezone', name='tz_name_uk'),
|
||||
schema = "updates")
|
||||
tablelist.append(countries)
|
||||
tvupdates = Table('tvupdates', metadata,
|
||||
Column('seriesid', BIGINT, primary_key = True),
|
||||
Column('timestamp', VARCHAR(15)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvupdates)
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
print('Creating Temporary Data Tables')
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
print('Dropping temporary update tables.')
|
||||
for table in tablelist:
|
||||
try:
|
||||
print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
@@ -0,0 +1,39 @@
|
||||
import sqlalchemy
|
||||
import progressbar
|
||||
from tvmaze.Processor import loadjson
|
||||
|
||||
class Updater():
|
||||
def __init__(self):
|
||||
global jprocess
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class tvupdates():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def update_tables(engine, updatesapi, tablename):
|
||||
jprocess = loadjson()
|
||||
print('Now retrieving available updates.')
|
||||
print('Creating update transaction.')
|
||||
ins = tablename.insert()
|
||||
seriesupdates = jprocess.load(updatesapi)
|
||||
updatelist = []
|
||||
seriesrange = len(seriesupdates)
|
||||
with progressbar.ProgressBar(maxval=seriesrange, redirect_stdout=True) as p:
|
||||
for key, value in seriesupdates.items():
|
||||
i = int(key)
|
||||
updater = {}
|
||||
updater['seriesid'] = key
|
||||
updater['timestamp'] = value
|
||||
updatelist.append(updater)
|
||||
if i <= seriesrange:
|
||||
p.update(i)
|
||||
#time.sleep(0.1)
|
||||
print('Update of tvupdates table is complete.')
|
||||
print('Done.')
|
||||
return(ins, updatelist)
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
@@ -0,0 +1,80 @@
|
||||
import sqlalchemy
|
||||
import progressbar
|
||||
import psycopg2.errors
|
||||
|
||||
class Update():
|
||||
def __init__(self):
|
||||
global jprocess
|
||||
|
||||
def rawexec(self, sqlquery):
|
||||
connection = engine.connect()
|
||||
try:
|
||||
trans = connection.begin()
|
||||
connection.execute(str(sqlquery))
|
||||
except:
|
||||
trans.rollback()
|
||||
else:
|
||||
trans.commit()
|
||||
connection.close()
|
||||
|
||||
def fileexec(self, sqlfile):
|
||||
connection = engine.connect()
|
||||
trans = connection.begin()
|
||||
for line in sqlfile:
|
||||
sqlquery = sqlquery + str(line)
|
||||
try:
|
||||
connection.execute(str(sqlquery))
|
||||
except:
|
||||
trans.rollback()
|
||||
lprint.logprint('error', 'Rollback for filename: ' + str(sqlfile))
|
||||
sqlfile.close()
|
||||
connection.close()
|
||||
else:
|
||||
trans.commit()
|
||||
sqlfile.close()
|
||||
connection.close()
|
||||
|
||||
def ormexec(self, listing, tablename):
|
||||
try:
|
||||
ins = tablename.insert()
|
||||
result = engine.execute(ins, listing)
|
||||
except sqlalchemy.exc.IntegrityError as ie:
|
||||
if 'UNIQUE KEY' in ie.args[0]:
|
||||
return True
|
||||
except psycopg2.errors.UniqueViolation as ie2:
|
||||
if 'unique constraint' in ie.args[0]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class tvupdates():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def update_tables(engine, updatesapi, tablename):
|
||||
jprocess = loadjson()
|
||||
print('Now retrieving available updates.')
|
||||
print('Creating update transaction.')
|
||||
ins = tablename.insert()
|
||||
seriesupdates = jprocess.load(updatesapi)
|
||||
updatelist = []
|
||||
seriesrange = len(seriesupdates)
|
||||
with progressbar.ProgressBar(maxval=seriesrange, redirect_stdout=True) as p:
|
||||
for key, value in seriesupdates.items():
|
||||
i = int(key)
|
||||
updater = {}
|
||||
updater['seriesid'] = key
|
||||
updater['timestamp'] = value
|
||||
updatelist.append(updater)
|
||||
if i <= seriesrange:
|
||||
p.update(i)
|
||||
#time.sleep(0.1)
|
||||
print('Update of tvupdates table is complete.')
|
||||
print('Done.')
|
||||
return(ins, updatelist)
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
@@ -0,0 +1,309 @@
|
||||
import datetime
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy import DateTime
|
||||
|
||||
class SQLGenerate():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def merge_series(self):
|
||||
seriessql = text('''
|
||||
INSERT INTO dbo.seriesdata (serieslink, url, thetvdb, tvrage, imdb,
|
||||
genres, seriesid, medium,original, language, name, webchannelid, networkid, premiered, rating, runtime, days, time,
|
||||
status, summary, type, weight) SELECT serieslink, url, thetvdb, tvrage, imdb,
|
||||
genres, seriesid, medium,original, language, name, webchannelid, networkid, premiered, rating, runtime, days, time,
|
||||
status, summary, type, weight from updates.newseriesdata
|
||||
ON CONFLICT(seriesid) DO UPDATE
|
||||
SET serieslink = excluded.serieslink,
|
||||
url = excluded.url,
|
||||
thetvdb = excluded.thetvdb,
|
||||
tvrage = excluded.tvrage,
|
||||
genres = excluded.genres,
|
||||
seriesid = excluded.seriesid,
|
||||
medium = excluded.medium,
|
||||
original = excluded.original,
|
||||
language = excluded.language,
|
||||
name = excluded.name,
|
||||
webchannelid = excluded.webchannelid,
|
||||
networkid = excluded.networkid,
|
||||
premiered = excluded.premiered,
|
||||
rating = excluded.rating,
|
||||
runtime = excluded.runtime,
|
||||
days = excluded.days,
|
||||
time = excluded.time,
|
||||
status = excluded.status,
|
||||
summary = excluded.summary,
|
||||
type = excluded.type,
|
||||
weight = excluded.weight;
|
||||
''')
|
||||
return(seriessql)
|
||||
|
||||
def merge_episodes(self):
|
||||
episodesql = text('''
|
||||
INSERT INTO dbo.epdata (episodeid,
|
||||
seriesid,
|
||||
season,
|
||||
episodenumber,
|
||||
episodename,
|
||||
airdate,
|
||||
airtime,
|
||||
episodesummary,
|
||||
airstamp,
|
||||
runtime,
|
||||
eplink,
|
||||
mediumimage,
|
||||
originalimage,
|
||||
"url")
|
||||
SELECT episodeid,
|
||||
seriesid,
|
||||
season,
|
||||
episodenumber,
|
||||
episodename,
|
||||
airdate,
|
||||
airtime,
|
||||
episodesummary,
|
||||
airstamp,
|
||||
runtime,
|
||||
eplink,
|
||||
mediumimage,
|
||||
originalimage,
|
||||
"url"
|
||||
FROM updates.newepdata
|
||||
ON CONFLICT (seriesid, episodeid) do UPDATE
|
||||
SET episodeid = excluded.episodeid,
|
||||
seriesid = excluded.seriesid,
|
||||
season = excluded.season,
|
||||
episodenumber = excluded.episodenumber,
|
||||
episodename = excluded.episodename,
|
||||
airdate = excluded.airdate,
|
||||
airtime = excluded.airtime,
|
||||
episodesummary = excluded.episodesummary,
|
||||
airstamp = excluded.airstamp,
|
||||
runtime = excluded.runtime,
|
||||
eplink = excluded.eplink,
|
||||
mediumimage = excluded.mediumimage,
|
||||
originalimage = excluded.originalimage,
|
||||
"url" = excluded."url";
|
||||
''')
|
||||
return(episodesql)
|
||||
|
||||
def merge_updates(self):
|
||||
updatesql = text('''
|
||||
INSERT INTO updates.tvupdatedata(seriesid, timestamp)
|
||||
SELECT seriesid, timestamp from updates.tvupdates
|
||||
ON CONFLICT(seriesid) DO UPDATE
|
||||
SET seriesid = excluded.seriesid, timestamp = excluded.timestamp;
|
||||
''')
|
||||
return(updatesql)
|
||||
|
||||
def merge_cast(self):
|
||||
datetimestamp = DateTime(datetime.datetime.utcnow)
|
||||
castsql = text('''
|
||||
INSERT INTO dbo.castdata (seriesid,characterid,actorid,charactername,mediumimage,originalimage,apilink,tvmazeilink)
|
||||
SELECT seriesid,characterid,actorid,charactername,mediumimage,originalimage,apilink,tvmazeilink
|
||||
FROM updates.newcastdata
|
||||
ON CONFLICT (seriesid, characterid, actorid) DO UPDATE
|
||||
SET seriesid = excluded.seriesid,
|
||||
characterid = excluded.characterid,
|
||||
actorid = excluded.actorid,
|
||||
charactername = excluded.charactername,
|
||||
mediumimage = excluded.mediumimage,
|
||||
originalimage = excluded.originalimage,
|
||||
apilink = excluded.apilink,
|
||||
tvmazeilink = excluded.tvmazeilink
|
||||
''')
|
||||
return(castsql)
|
||||
|
||||
def merge_actors(self):
|
||||
actorsql = text('''
|
||||
INSERT INTO dbo.actors (actorid,actorname,countryname,countrytimezone,birthday,deathday,gender,mediumimage,originalimage,apilink,"url",countrycode)
|
||||
SELECT actorid,actorname,countryname,countrytimezone,birthday,deathday,gender,mediumimage,originalimage,apilink,"url",countrycode
|
||||
FROM updates.newactordata
|
||||
ON CONFLICT (actorid) DO UPDATE
|
||||
SET actorid = excluded.actorid,
|
||||
actorname = excluded.actorname,
|
||||
countryname = excluded.countryname,
|
||||
countrytimezone = excluded.countrytimezone,
|
||||
birthday = excluded.birthday,
|
||||
deathday = excluded.deathday,
|
||||
gender = excluded.gender,
|
||||
mediumimage = excluded.mediumimage,
|
||||
originalimage = excluded.originalimage,
|
||||
apilink = excluded.apilink,
|
||||
"url" = excluded."url",
|
||||
countrycode = excluded.countrycode;
|
||||
''')
|
||||
return(actorsql)
|
||||
|
||||
def merge_crew(self):
|
||||
crewsql = text('''
|
||||
INSERT INTO dbo.crewdata
|
||||
(seriesid,
|
||||
crewid,
|
||||
countryid,
|
||||
type,
|
||||
name,
|
||||
medium,
|
||||
original,
|
||||
apilink,
|
||||
gender,
|
||||
birthday,
|
||||
deathday)
|
||||
SELECT seriesid,
|
||||
crewid,
|
||||
countryid,
|
||||
type,
|
||||
name,
|
||||
medium,
|
||||
original,
|
||||
apilink,
|
||||
gender,
|
||||
birthday,
|
||||
deathday
|
||||
FROM updates.newcrewdata
|
||||
ON CONFLICT (seriesid, crewid, type) DO UPDATE
|
||||
SET seriesid = excluded.seriesid,
|
||||
crewid = excluded.crewid,
|
||||
countryid = excluded.countryid,
|
||||
type = excluded.type,
|
||||
name = excluded.name,
|
||||
medium = excluded.medium,
|
||||
original = excluded.original,
|
||||
apilink = excluded.apilink,
|
||||
gender = excluded.gender,
|
||||
birthday = excluded.birthday,
|
||||
deathday = excluded.deathday;
|
||||
''')
|
||||
return(crewsql)
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
class Merger():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class Charactermerge():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def merge(self, engine):
|
||||
castsql = text('''MERGE dbo.castdata as N
|
||||
USING updates.newcastdata as O
|
||||
ON N.seriesid = O.seriesid and N.characterid = O.characterid and N.actorid = O.actorid
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET N.seriesid = O.seriesid, N.characterid = O.characterid,N.actorid = O.actorid,N.charactername = O.charactername,N.mediumimage = O.mediumimage,N.originalimage = O.originalimage,N.apilink = O.apilink,N.tvmazelink = O.tvmazelink, N.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (seriesid,characterid,actorid,charactername,mediumimage,originalimage,apilink,tvmazelink, created_on)
|
||||
VALUES
|
||||
(O.seriesid,O.characterid,O.actorid,O.charactername,O.mediumimage,O.originalimage,O.apilink,O.tvmazelink, GETDATE());
|
||||
SELECT * FROM updates.newcastdata;
|
||||
''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(castsql)
|
||||
#engine.commit()
|
||||
|
||||
actorsql = text('''MERGE dbo.actors as N
|
||||
USING updates.newactordata as O
|
||||
ON N.actorid = O.actorid
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET N.actorid = O.actorid, N.actorname = O.actorname, N.countryname = O.countryname, N.countrytimezone = O.countrytimezone, N.birthday = O.birthday, N.deathday = O.deathday, N.gender = O.gender, N.mediumimage = O.mediumimage, N.originalimage = O.originalimage, N.apilink = O.apilink, N.url = O.url, N.countrycode = O.countrycode, N.updated_on = GETDATE()
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (actorid,actorname,countryname,countrytimezone,birthday,deathday,gender,mediumimage,originalimage,apilink,url,countrycode,created_on)
|
||||
VALUES
|
||||
(O.actorid,O.actorname,O.countryname,O.countrytimezone,O.birthday,O.deathday,O.gender,O.mediumimage,O.originalimage,O.apilink,O.url,O.countrycode, GETDATE());
|
||||
SELECT * FROM updates.newactordata;
|
||||
''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(actorsql)
|
||||
#engine.commit()
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class Updatemerge():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def merge(self, engine):
|
||||
updatesql = text('''INSERT INTO updates.tvupdatedata (seriesid, timestamp)
|
||||
select seriesid, timestamp from updates.tvupdates
|
||||
ON CONFLICT (seriesid)
|
||||
DO
|
||||
UPDATE
|
||||
SET seriesid = EXCLUDED.seriesid, timestamp = EXCLUDED.timestamp;''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(updatesql)
|
||||
#engine.commit()
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
class Jsonmerge():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def merge(self, engine):
|
||||
seriessql = text('''INSERT INTO "[updates]".tvmaze_seriesjson (seriesid, jdata, created_on)
|
||||
select seriesid, jdata, date_trunc('minute', current_timestamp) FROM "[updates]".seriesjsonnewvals
|
||||
ON CONFLICT (seriesid)
|
||||
DO
|
||||
update
|
||||
SET seriesid = EXCLUDED.seriesid, jdata = EXCLUDED.jdata, updated_on = date_trunc('minute', current_timestamp);
|
||||
''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(seriessql)
|
||||
#engine.commit()
|
||||
|
||||
episodesql = text('''INSERT INTO "[updates]".tvmaze_episodejson (seriesid, jdata, created_on)
|
||||
select seriesid, jdata, date_trunc('minute', current_timestamp) FROM "[updates]".episodejsonnewvals
|
||||
ON CONFLICT (seriesid)
|
||||
DO
|
||||
update
|
||||
SET seriesid = EXCLUDED.seriesid, jdata = EXCLUDED.jdata, updated_on = date_trunc('minute', current_timestamp);
|
||||
''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(episodesql)
|
||||
#engine.commit()
|
||||
|
||||
charactersql = text('''INSERT INTO "[updates]".tvmaze_characterjson (seriesid, jdata, created_on)
|
||||
select seriesid, jdata, date_trunc('minute', current_timestamp) FROM "[updates]".characterjsonnewvals
|
||||
ON CONFLICT (seriesid)
|
||||
DO
|
||||
update
|
||||
SET seriesid = EXCLUDED.seriesid, jdata = EXCLUDED.jdata, updated_on = date_trunc('minute', current_timestamp);
|
||||
''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(charactersql)
|
||||
#engine.commit()
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class Episodemerge():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def merge(self, engine):
|
||||
episodesql = text('''INSERT INTO dbo.epdata (episodeid,seriesid,season,episodenumber,episodename,airdate,airtime,episodesummary,airstamp,runtime,eplink,mediumimage,originalimage,url, created_on)
|
||||
select episodeid,seriesid,season,episodenumber,episodename,airdate,airtime,episodesummary,airstamp,runtime,eplink,mediumimage,originalimage,url, date_trunc('minute', current_timestamp) FROM "[updates]".newepdata
|
||||
ON CONFLICT (episodeid)
|
||||
DO
|
||||
UPDATE
|
||||
SET episodeid = EXCLUDED.episodeid, seriesid = EXCLUDED.seriesid, season = EXCLUDED.season, episodenumber = EXCLUDED.episodenumber, episodename = EXCLUDED.episodename,
|
||||
airdate = EXCLUDED.airdate, airtime = EXCLUDED.airtime, episodesummary = EXCLUDED.episodesummary, airstamp = EXCLUDED.airstamp, runtime = EXCLUDED.runtime,
|
||||
eplink = EXCLUDED.eplink, mediumimage = EXCLUDED.mediumimage, originalimage = EXCLUDED.originalimage, url = EXCLUDED.url, updated_on = date_trunc('minute', current_timestamp);''')
|
||||
with engine.connect() as con:
|
||||
rs = con.execute(episodesql)
|
||||
#engine.commit()
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,376 @@
|
||||
import sqlalchemy
|
||||
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, Sequence, text, UniqueConstraint
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.schema import MetaData
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.types import *
|
||||
|
||||
class Tables():
|
||||
def __init__(self):
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global metadata
|
||||
global engine
|
||||
global session
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global tvupdates
|
||||
global newseriesdata
|
||||
global actorlinks
|
||||
global tablelist
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
class Createtables():
|
||||
|
||||
def __init__(self, session, metadata, engine, tablelist):
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
session.commit()
|
||||
#self.send(tablelist)
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
newseriesdata = Table('newseriesdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newseriesdata_id_seq'), primary_key = True),
|
||||
Column('seriesid',INTEGER, unique=True),
|
||||
Column('tvdbid', String(25)),
|
||||
Column('tvrageid', String(25)),
|
||||
Column('imdbid', String(25)),
|
||||
Column('serieslanguage', String(25)),
|
||||
Column('genres', String(75)),
|
||||
Column('seriesname', String(150)),
|
||||
Column('seriesstatus', String(25)),
|
||||
Column('premiered', String(25)),
|
||||
Column('airdays', String(72)),
|
||||
Column('airtime', String(25)),
|
||||
Column('runtime', String(25)),
|
||||
Column('rating', String(25)),
|
||||
Column('showtype',TEXT),
|
||||
Column('overview',TEXT),
|
||||
Column('mediumimage',TEXT),
|
||||
Column('originalimage',TEXT),
|
||||
Column('weight',INTEGER),
|
||||
Column('networkid', BIGINT),
|
||||
Column('webchannelid', BIGINT),
|
||||
Column('officialsite',TEXT),
|
||||
Column('showurl',TEXT),
|
||||
Column('apilink',TEXT),
|
||||
schema = "updates")
|
||||
tablelist.append(newseriesdata)
|
||||
newactordata = Table('newactordata', metadata,
|
||||
Column('id', BIGINT, Sequence('newactordata_id_seq'), primary_key = True),
|
||||
Column('actorid', INTEGER, unique=True),
|
||||
Column('actorname', VARCHAR(72)),
|
||||
Column('countryname', VARCHAR(144)),
|
||||
Column('countrytimezone', VARCHAR(72)),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(6)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('countrycode', VARCHAR(12)),
|
||||
schema = "updates")
|
||||
tablelist.append(newactordata)
|
||||
newepdata = Table('newepdata', metadata,
|
||||
#Column('id', BIGINT, Sequence('newepdata_id_seq'), primary_key = True),
|
||||
Column('episodeid', INTEGER),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('season', INTEGER),
|
||||
Column('episodenumber', INTEGER),
|
||||
Column('episodename', TEXT),
|
||||
Column('airdate', VARCHAR(32)),
|
||||
Column('airtime', VARCHAR(32)),
|
||||
Column('episodesummary', TEXT),
|
||||
Column('airstamp', VARCHAR(32)),
|
||||
Column('runtime', VARCHAR(6)),
|
||||
Column('eplink', TEXT),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
schema = "updates")
|
||||
tablelist.append(newepdata)
|
||||
newcastdata = Table('newcastdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newcastdata_id_seq'), primary_key = True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('characterid', INTEGER),
|
||||
Column('actorid', INTEGER),
|
||||
Column('charactername', VARCHAR(250)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('tvmazelink', TEXT),
|
||||
schema = "updates")
|
||||
tablelist.append(newcastdata)
|
||||
tvnetworks = Table('tvnetworkdata', metadata,
|
||||
Column('id', BIGINT, Sequence('network_id_seq'), primary_key = True),
|
||||
Column('networkid', String(12)),
|
||||
Column('networkname', String(255)),
|
||||
Column('country', String(255)),
|
||||
Column('countrycode', String(4)),
|
||||
Column('countrytimezone', String(25)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvnetworks)
|
||||
tvwebchannels = Table('tvwebchanneldata', metadata,
|
||||
Column('id', BIGINT, Sequence('webchannel_id_seq'), primary_key = True),
|
||||
Column('webchannelname', String(255)),
|
||||
Column('webchannelcountrycode', String(4)),
|
||||
Column('webchannelcountryname', String(255)),
|
||||
Column('webchannelcountrytimezone', String(4)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvwebchannels)
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
print('Creating Temporary Data Tables')
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
for table in tablelist:
|
||||
try:
|
||||
#print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
|
||||
class Temptables():
|
||||
|
||||
def __init__(self, session, metadata, engine, tablelist):
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
#session.commit()
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
tvnetworknewvals = Table('tvnetworknewvals', metadata,
|
||||
Column('id', BIGINT, Sequence('network_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvnetworknewvals)
|
||||
tvwebchannelnewvals = Table('tvwebchannelnewvals', metadata,
|
||||
Column('id', BIGINT, Sequence('webchannel_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(4)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvwebchannelnewvals)
|
||||
tvupdates = Table('tvupdates', metadata,
|
||||
Column('seriesid', BIGINT, primary_key = True),
|
||||
Column('timestamp', VARCHAR(15)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvupdates)
|
||||
tvupdatedata = Table('tvupdatedata', metadata,
|
||||
Column('seriesid', BIGINT, primary_key = True),
|
||||
Column('timestamp', VARCHAR(15)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvupdatedata)
|
||||
newactorlinks = Table('newactorlinks', metadata,
|
||||
Column('id', BIGINT, Sequence('tempepisodejson_id_seq'), primary_key = True),
|
||||
Column('actorid', INTEGER),
|
||||
Column('characterid', INTEGER),
|
||||
schema = "updates")
|
||||
tablelist.append(newactorlinks)
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
tablelist.remove(tablelist[6])
|
||||
print('Creating Temporary JSON Tables')
|
||||
try:
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
except sqlalchemy.exc.ProgrammingError as pe:
|
||||
pass
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
for table in tablelist:
|
||||
if 'tvupdatedata' in table.description:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
#print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
#session.commit()
|
||||
|
||||
class CreateTempTables():
|
||||
|
||||
global tvnetworknewvals
|
||||
global tvwebchannelnewvals
|
||||
global characterjsonnewvals
|
||||
global seriesjsonnewvals
|
||||
global episodejsonnewvals
|
||||
global metadata
|
||||
global engine
|
||||
global session
|
||||
|
||||
global tablelist
|
||||
|
||||
def __init__(self, session, metadata, engine, tablelist):
|
||||
Base = declarative_base(metadata = metadata)
|
||||
self.tablelist = self.settables(metadata, engine)
|
||||
try:
|
||||
self.drop(session, self.tablelist)
|
||||
except:
|
||||
pass
|
||||
self.create(Base, engine, metadata, session, self.tablelist)
|
||||
session.commit()
|
||||
#self.send(tablelist)
|
||||
|
||||
def settables(self, metadata, engine):
|
||||
tablelist = []
|
||||
newseriesdata = Table('newseriesdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newseriesdata_id_seq'), primary_key = True),
|
||||
Column('seriesid',INTEGER, unique=True),
|
||||
Column('thetvdb', String(25)),
|
||||
Column('tvrage', String(25)),
|
||||
Column('imdb', String(25)),
|
||||
Column('language', String(25)),
|
||||
Column('genres', String(75)),
|
||||
Column('name', String(150)),
|
||||
Column('status', String(25)),
|
||||
Column('premiered', String(25)),
|
||||
Column('days', String(72)),
|
||||
Column('time', String(25)),
|
||||
Column('runtime', String(25)),
|
||||
Column('rating', String(25)),
|
||||
Column('type',TEXT),
|
||||
Column('summary',TEXT),
|
||||
Column('medium',TEXT),
|
||||
Column('original',TEXT),
|
||||
Column('weight',INTEGER),
|
||||
Column('networkid', BIGINT),
|
||||
Column('webchannelid', BIGINT),
|
||||
Column('officialsite',TEXT),
|
||||
Column('url',TEXT),
|
||||
Column('serieslink',TEXT),
|
||||
schema="updates")
|
||||
tablelist.append(newseriesdata)
|
||||
newactordata = Table('newactordata', metadata,
|
||||
Column('id', BIGINT, Sequence('newactordata_id_seq'), primary_key = True),
|
||||
Column('actorid', INTEGER, unique=True),
|
||||
Column('actorname', VARCHAR(72)),
|
||||
Column('countryname', VARCHAR(36)),
|
||||
Column('countrytimezone', VARCHAR(72)),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(6)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('countrycode', VARCHAR(12)),
|
||||
schema="updates")
|
||||
tablelist.append(newactordata)
|
||||
newepdata = Table('newepdata', metadata,
|
||||
#Column('id', BIGINT, Sequence('newepdata_id_seq'), primary_key = True),
|
||||
Column('episodeid', INTEGER),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('season', INTEGER),
|
||||
Column('episodenumber', INTEGER),
|
||||
Column('episodename', TEXT),
|
||||
Column('airdate', VARCHAR(32)),
|
||||
Column('airtime', VARCHAR(32)),
|
||||
Column('episodesummary', TEXT),
|
||||
Column('airstamp', VARCHAR(32)),
|
||||
Column('runtime', VARCHAR(6)),
|
||||
Column('eplink', TEXT),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('url', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
schema="updates")
|
||||
tablelist.append(newepdata)
|
||||
newcastdata = Table('newcastdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newcastdata_id_seq'), primary_key = True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('characterid', INTEGER),
|
||||
Column('actorid', INTEGER),
|
||||
Column('url', TEXT),
|
||||
Column('charactername', VARCHAR(128)),
|
||||
Column('mediumimage', TEXT),
|
||||
Column('originalimage', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
Column('tvmazelink', TEXT),
|
||||
Column('self', CHAR),
|
||||
Column('voice', CHAR),
|
||||
schema="updates")
|
||||
tablelist.append(newcastdata)
|
||||
newcrewdata = Table('newcrewdata', metadata,
|
||||
Column('id', BIGINT, Sequence('newcrewdata_id_seq'), primary_key = True),
|
||||
Column('seriesid', INTEGER),
|
||||
Column('crewid', INTEGER),
|
||||
Column('type', VARCHAR(128)),
|
||||
Column('url', TEXT),
|
||||
Column('name', VARCHAR(256)),
|
||||
Column('countryid', INTEGER),
|
||||
Column('birthday', DATE),
|
||||
Column('deathday', DATE),
|
||||
Column('gender', VARCHAR(24)),
|
||||
Column('medium', TEXT),
|
||||
Column('original', TEXT),
|
||||
Column('apilink', TEXT),
|
||||
UniqueConstraint('seriesid', 'crewid', 'type', name='crew_unique'),
|
||||
schema="updates")
|
||||
tablelist.append(newcrewdata)
|
||||
tvnetworks = Table('tvnetworkdata', metadata,
|
||||
Column('id', BIGINT, Sequence('network_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvnetworks)
|
||||
tvwebchannels = Table('tvwebchanneldata', metadata,
|
||||
Column('id', BIGINT, Sequence('webchannel_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('countryid', String(255)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvwebchannels)
|
||||
countries = Table('newcountrydata', metadata,
|
||||
Column('id', BIGINT, Sequence('country_id_seq'), primary_key = True),
|
||||
Column('name', String(255)),
|
||||
Column('code', String(255)),
|
||||
Column('timezone', String(255)),
|
||||
UniqueConstraint('name', 'timezone', name='tz_name_uk'),
|
||||
schema = "updates")
|
||||
tablelist.append(countries)
|
||||
tvupdates = Table('tvupdates', metadata,
|
||||
Column('seriesid', BIGINT, primary_key = True),
|
||||
Column('timestamp', VARCHAR(15)),
|
||||
schema = "updates")
|
||||
tablelist.append(tvupdates)
|
||||
return(tablelist)
|
||||
|
||||
def create(self, Base, engine, metadata, session, tablelist):
|
||||
print('Creating Temporary Data Tables')
|
||||
Base.metadata.create_all(engine, tables=tablelist)
|
||||
|
||||
def drop(self, session, tablelist):
|
||||
print('Dropping temporary update tables.')
|
||||
for table in tablelist:
|
||||
try:
|
||||
print('Dropping ' + str(table))
|
||||
table.drop()
|
||||
except sqlalchemy.exc.ProgrammingError as se:
|
||||
pass
|
||||
@@ -0,0 +1,39 @@
|
||||
import sqlalchemy
|
||||
import progressbar
|
||||
from tvmaze.Processor import loadjson
|
||||
|
||||
class Updater():
|
||||
def __init__(self):
|
||||
global jprocess
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
class tvupdates():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def update_tables(engine, updatesapi, tablename):
|
||||
jprocess = loadjson()
|
||||
print('Now retrieving available updates.')
|
||||
print('Creating update transaction.')
|
||||
ins = tablename.insert()
|
||||
seriesupdates = jprocess.load(updatesapi)
|
||||
updatelist = []
|
||||
seriesrange = len(seriesupdates)
|
||||
with progressbar.ProgressBar(maxval=seriesrange, redirect_stdout=True) as p:
|
||||
for key, value in seriesupdates.items():
|
||||
i = int(key)
|
||||
updater = {}
|
||||
updater['seriesid'] = key
|
||||
updater['timestamp'] = value
|
||||
updatelist.append(updater)
|
||||
if i <= seriesrange:
|
||||
p.update(i)
|
||||
#time.sleep(0.1)
|
||||
print('Update of tvupdates table is complete.')
|
||||
print('Done.')
|
||||
return(ins, updatelist)
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
@@ -0,0 +1,71 @@
|
||||
__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'
|
||||
)
|
||||
]
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user