Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os,xml.dom.minidom
- class general:
- def __init__(self, code=0):
- self.__code=code
- def setCode(self, value): self.__code=value
- def getCode(self):return self.__code
- class namee:
- def __init__(self, name=''):
- self.__name=name
- def setName(self, value): self.__name=value
- def getName(self):return self.__name
- class author(namee, general):
- def __init__ (self,code=0, surname='', name=''):
- general.__init__(self, code)
- namee.__init__(self, name)
- self.__surname = surname
- def setSurname(self, value): self.__surname=value
- def getSurname(self):return self.__surname
- def getAuthor(self):
- s1="%s %s" % (self.getSurname(), self.getName())
- return s1
- Author1=author(surname='Ishigami', name='Oda', code=2)
- Author2=author(surname='Masashi', name='Kimoto', code=3)
- class studio(namee, general):
- def __init__(self, code=0, name='', website='', country=''):
- namee.__init__(self, name)
- general.__init__(self, code)
- self.__website = website
- self.__country = country
- self.__name = name
- def getWebsite(self):return self.__website
- def getName(self):return self.__name
- def getCountry(self):return self.__country
- def getStudio(self):
- s5="%s %s %s" % (self.getName(), self.getCountry(), self.getWebsite())
- return s5
- Studio1=studio('Toei Animation',2, 'http://www.toei-anim.co.jp/', 'China')
- Studio2=studio('Studio Pierrot',3, 'pierrot.jp', 'Japan')
- class animation(namee, general):
- def __init__ (self, author=None, studio=None ,name='', code=0, zhanr='', year=0, episode=0):
- namee.__init__(self, name)
- general.__init__(self, code)
- self.__author = author
- self.__studio = studio
- self.__zhanr = zhanr
- self.__year = year
- self.__episode = episode
- def setZhanr(self, value): self.__zhanr=value
- def getZhanr(self):return self.__zhanr
- def setYear(self, value): self.__year=value
- def getYear(self):return self.__year
- def setEpisode(self, value): self.__episode=value
- def getEpisode(self):return self.__episode
- def getAuthorCode(self):
- if self.__author:return self.__author.getCode()
- def getStudioCode(self):
- if self.__studio:return self.__studio.getCode()
- def getAnimation(self):
- s = "%s %s %s %s %s %s" % (self.__author.getAuthor(),self.__studio.getStudio(), self.getName(), self.getZhanr(), self.getYear(), self.getEpisode())
- return s
- class generalList:
- def __init__(self):self.__list=[]
- def clear(self):self.__list=[]
- def findByCode(self,code):
- for l in self.__list:
- if l.getCode()==code:
- return l
- break
- def getCodes(self):return [s.getCode() for s in self.__list]
- def appendList(self,value):self.__list.append(value)
- def removeList(self,code):
- for s in self.__list:
- if s.getCode()==code:self.__list.remove(s)
- def getName(self,code):return self.findByCode(code).getName()
- class authorList(generalList):
- def getSurname(self,code):return self.findByCode(code).getSurname()
- def getName(self,code):return self.findByCode(code).getName()
- def getAuthorList(self, code):
- s3="%s %s" % (self.findByCode(code).getSurname(), self.findByCode(code).getName())
- return s3
- class studioList(generalList):
- def getWebsite(self,code):return self.findByCode(code).getWebsite()
- def getName(self,code):return self.findByCode(code).getName()
- def getCountry(self,code):return self.findByCode(code).getCountry()
- def getStudioList(self,code):
- s5="%s %s %s" % (self.findByCode(code).getName(), self.findByCode(code).getCountry(), self.findByCode(code).getWebsite())
- return s5
- class animationList(generalList):
- def getZhanr(self,code):return self.findByCode(code).getZhanr()
- def getEpisode(self,code):return self.findByCode(code).getEpisode()
- def getYear(self, code):return self.findByCode(code).getYear()
- def getName(self,code):return self.findByCode(code).getName()
- def getAnimationList(self, code):
- s13="%s %s %s %s" % (self.findByCode(code).getName(), self.findByCode(code).getZhanr(), self.findByCode(code).getEpisode(), self.findByCode(code).getYear())
- return s13
- class generalListEdit(generalList):
- def getNewCode(self):
- m=0
- for c in self.getCodes():
- if c>m:m=c
- return m+1
- def setName(self,code,value):return self.findByCode(code).setName(value)
- class AuthorListEdit(authorList,generalListEdit):
- def newRec(self,code=0,surname='',name=''):self.appendList(author(code,surname,name))
- def setSurname(self,code,value):self.findByCode(code).setSurname(value)
- def setName(self,code,value):self.findByCode(code).setName(value)
- def removeAuthor(self,code):self.__Authors.removeList(code)
- class StudioListEdit(studioList,generalListEdit):
- def newRec(self,code=0,name='',website='',country=''):self.appendList(studio(code, name, website,country))
- def setWebsite(self,code,value):self.findByCode(code).setWebsite(value)
- def setCountry(self,code,value):self.findByCode(code).setCountry(value)
- def setName(self,code,value):self.findByCode(code).setName(value)
- class AnimationListEdit(animationList,generalListEdit):
- def newRec(self,author, studio ,name='', code=0, zhanr='', year=0, episode=0):
- self.appendList(animation(author, studio ,name, code, zhanr, year, episode))
- def setAuthor(self,code,value):self.findByCode(code).setAuthor(value)
- def setStudio(self,code,value):self.findByCode(code).setStudio(value)
- def setZhanr(self,code,value):self.findByCode(code).setZhanr(value)
- def setYear(self,code,value):self.findByCode(code).setYear(value)
- def setEpisode(self,code,value):self.findByCode(code).setEpisode(value)
- def getZhanr(self,code):return self.findByCode(code).getZhanr()
- def getYear(self,code):return self.findByCode(code).getYear()
- def getEpisode(self,code):return self.findByCode(code).getEpisode()
- def getAuthorCode(self,code):return self.findByCode(code).getAuthorCode()
- def getAuthorSurname(self,code):return self.findByCode(code).getAuthorSurname()
- def getAuthorName(self,code):return self.findByCode(code).getAuthorName()
- def getStudioCode(self,code):return self.findByCode(code).getStudioCode()
- def getStudioName(self,code):return self.findByCode(code).getStudioName()
- def getStudioWebsite(self,code):return self.findByCode(code).getStudioWebsite()
- def getStudioCountry(self,code):return self.findByCode(code).getStudioCountry()
- class library:
- def __init__(self):
- self.__Animations=AnimationListEdit()
- self.__Studios=StudioListEdit()
- self.__Authors=AuthorListEdit()
- def removeAuthor(self,code):
- self.__Authors.removeList(code)
- def removeStudio(self,code):
- self.__Studios.removeList(code)
- def clear(self):
- self.__Animations.clear()
- self.__Authors.clear()
- self.__Studios.clear()
- def newAuthor(self,code=0,surname='',name=''):self.__Authors.newRec(code,surname,name)
- def findAuthorByCode(self,code):return self.__Authors.findByCode(code)
- def getAuthorNewCode(self):return self.__Authors.getNewCode()
- def getAuthorCodes(self):return self.__Authors.getCodes()
- def getAuthorName(self,code):return self.__Authors.getName(code)
- def getAuthorSurname(self,code):return self.__Authors.getSurname(code)
- def setAuthorName(self,code,value):self.__Authors.setName(code,value)
- def setAuthorSurname(self,code,value):self.__Authors.setSurname(code,value)
- def newStudio(self,code=0,name='',website='',country=''):self.__Studios.newRec(code, name, website, country)
- def findStudioByCode(self,code):return self.__Studios.findByCode(code)
- def getStudioNewCode(self):return self.__Studios.getNewCode()
- def getStudioCodes(self):return self.__Studios.getCodes()
- def getStudioCountry(self,code):return self.__Studios.getCountry(code)
- def getStudioWebsite(self,code):return self.__Studios.getWebsite(code)
- def getStudioName(self,code):return self.__Studios.getName(code)
- def setStudioCountry(self,code,value):self.__Studios.setCountry(code,value)
- def setStudioWebsite(self,code,value):self.__Studios.setWebsite(code,value)
- def setStudioName(self,code,value):self.__Studios.setName(code,value)
- def removeAnimation(self,code):self.__Animations.removeList(code)
- def getAnimationNewCode(self):return self.__Animations.getNewCode()
- def removeAnimation(self,code):self.__Animations.removeList(code)
- def newAnimation(self,author, studio ,name='', code=0, zhanr='', year=0, episode=0):self.__Animations.newRec(author, studio ,name, code, zhanr, year, episode)
- def findAnimationByCode(self,code):return self.__Animation.findByCode(code)
- def setAnimationZhanr(self,code,value):self.__Animations.setZhanr(code,value)
- def setAnimationYear(self,code,value):self.__Animations.setYear(code,value)
- def setAnimationEpisode(self,code,value):self.__Animations.setEpisode(code,value)
- def setAnimationName(self,code,value):self.__Animations.setName(code,value)
- def setAnimationAuthor(self,code,pcode):self.__Animations.setAuthor(code, self.findAnimationByCode(pcode))
- def getAnimationZhanr(self,code):return self.__Animations.getZhanr(code)
- def getAnimationName(self,code):return self.__Animations.getName(code)
- def getAnimationYear(self,code):return self.__Animations.getYear(code)
- def getAnimationEpisode(self,code):return self.__Animations.getEpisode(code)
- def getAnimationAuthorCode(self,code):return self.__Animations.getAuthorCode(code)
- def getAnimationAuthorName(self,code):return self.__Animations.getAuthorName(code)
- def getAnimationAuthorSurname(self, code):return self.__Animations.getAuthorSurname(code)
- def getAnimationStudioName(self,code):return self.__Animations.getStudioName(code)
- def getAnimationStudioCountry(self,code):return self.__Animations.getStudioCountry(code)
- def getAnimationStudioWebsite(self,code):return self.__Animations.getWebsite(code)
- def getAnimationStudioCode(self,code):return self.__Animations.getStudioCode(code)
- def findAnimationByCode(self,code):return self.__Animations.findByCode(code)
- def getAnimationNewCode(self):return self.__Animations.getNewCode()
- def getAnimationCodes(self):return self.__Animations.getCodes()
- def getAll(self, code):
- s10="%s %s %s" % (self.__Authors.getAuthorList(code),self.__Studios.getStudioList(code), self.__Animations.getAnimationList(code))
- return s10
- Studio1=studio(name='utofable', code=1, website='wewewe.com', country='Japan')
- Author1=author(code=1,name='Suzuki', surname='Kyoshitsu')
- Animation1=animation(code=1, author=Author1, studio=Studio1,year=1980,zhanr='Senen',name='naruto',episode=200)
- l1=AuthorListEdit()
- l1.appendList(Author1)
- print(Animation1.getAuthorCode())
- l2=StudioListEdit()
- l2.appendList(Studio1)
- l3=AnimationListEdit()
- l3.appendList(Animation1)
- f1=library()
- f1.newAuthor(1, 'Suzuki', 'Kyoshitsu')
- print(f1.findAuthorByCode(1).getAuthor())
- f1.newStudio(1,'utofable','wewewe.com','Japan')
- print(f1.findStudioByCode(1).getStudio())
- f1.newAnimation (f1.findAuthorByCode(1),f1.findStudioByCode(1),'naruto',1,'Senen',1980,200)
- print(f1.findAnimationByCode(1).getAnimation())
- print(f1.getAnimationAuthorCode(1))
- print(f1.getAnimationCodes())
- print(f1.getAll(1))
- class dataxml:
- def read(self,inp,lib):
- dom=xml.dom.minidom.parse(inp)
- dom.normalize()
- for node in dom.childNodes[0].childNodes:
- if (node.nodeType==node.ELEMENT_NODE)and(node.nodeName=='author'):
- code,surname,name=0,"",""
- for t in node.attributes.items():
- if t[0]=="code":code=int(t[1])
- if t[0]=="name":name=t[1]
- if t[0]=="surname":surname=t[1]
- lib.newAuthor(code,surname,name)
- if (node.nodeType==node.ELEMENT_NODE)and(node.nodeName=='studio'):
- code,name, website, country=0,"","",""
- for t in node.attributes.items():
- if t[0]=="code":code=int(t[1])
- if t[0]=="name":name=t[1]
- if t[0]=="website":website=t[1]
- if t[0]=="country":country=t[1]
- lib.newStudio(code,name,website, country)
- if (node.nodeType==node.ELEMENT_NODE)and(node.nodeName=='animation'):
- author, studio, name, code, zhanr, year,episode=None,None,"",0,"",0,0
- for t in node.attributes.items():
- if t[0]=="author":author=lib.findAuthorByCode(int(t[1]))
- if t[0]=="studio":studio=lib.findStudioByCode(int(t[1]))
- if t[0]=="name":name=t[1]
- if t[0]=="code":code=int(t[1])
- if t[0]=="zhanr":zhanr=t[1]
- if t[0]=="year":year=int(t[1])
- if t[0]=="episode":episode=int(t[1])
- lib.newAnimation(author, studio, name, code, zhanr, year,episode)
- for n in node.childNodes:
- if (n.nodeType == n.ELEMENT_NODE)and(n.nodeName == "author"):
- for t in n.attributes.items():
- if t[0] == "code": author = sh.findAuthorByCode(int(t[1]))
- sh.appendAnimationAuthor(code, customer)
- for n in node.childNodes:
- if (n.nodeType == n.ELEMENT_NODE) and (n.nodeName == "studio"):
- for t in n.attributes.items():
- if t[0] == "code": studio = sh.findStudioByCode(int(t[1]))
- sh.appendAnimationStudio(code, product)
- def write(self,out,lib):
- dom=xml.dom.minidom.Document()
- root=dom.createElement("library")
- dom.appendChild(root)
- for c in lib.getAuthorCodes():
- aut=dom.createElement("author")
- aut.setAttribute('code',str(c))
- aut.setAttribute('surname',lib.getAuthorSurname(c))
- aut.setAttribute('name',lib.getAuthorName(c))
- root.appendChild(aut)
- for c in lib.getStudioCodes():
- stud=dom.createElement("studio")
- stud.setAttribute('name',lib.getStudioName(c))
- stud.setAttribute('code',str(c))
- stud.setAttribute('website',lib.getStudioWebsite(c))
- stud.setAttribute('country',lib.getStudioCountry(c))
- root.appendChild(stud)
- for c in lib.getAnimationCodes():
- anim=dom.createElement("animation")
- aut=dom.createElement("author")
- aut.setAttribute('code',str(lib.getAnimationAuthorCode(c)))
- stud=dom.createElement("studio")
- stud.setAttribute('code',str(lib.getAnimationStudioCode(c)))
- anim.setAttribute('name',lib.getAnimationName(c))
- anim.setAttribute('code',str(c))
- anim.setAttribute('zhanr',lib.getAnimationZhanr(c))
- anim.setAttribute('year',str(lib.getAnimationYear(c)))
- anim.setAttribute('episode',str(lib.getAnimationEpisode(c)))
- anim.appendChild(aut)
- anim.appendChild(stud)
- root.appendChild(anim)
- f = open(out,"wb")
- f.write(dom.toprettyxml(encoding='utf-8'))
- import os
- import sqlite3 as db
- emptydb = """
- PRAGMA foreign_keys = ON;
- create table author
- (code integer primary key,
- surname text,
- name text);
- create table studio
- (code integer primary key,
- name text,
- website text,
- country text);
- create table animation
- (author integer references author(code) on update cascade on delete set null,
- studio integer references studio(code) on update cascade on delete set null,
- code integer primary key,
- name text,
- zhanr text,
- year integer,
- episode integer);
- """
- class datasql:
- def read(self,inp,lib):
- conn = db.connect(inp)
- curs = conn.cursor()
- curs.execute('select code,surname,name from author')
- data=curs.fetchall()
- for r in data:lib.newAuthor(r[0],r[1],r[2])
- curs.execute('select code,name, website, country from studio')
- data=curs.fetchall()
- for r in data:lib.newStudio(r[0],r[1],r[2],r[3])
- curs.execute('select author, studio, name, code, zhanr, year,episode from animation')
- data=curs.fetchall()
- for r in data:lib.newAnimation(lib.findAuthorByCode(r[0]),lib.findStudioByCode(r[1]),r[2],r[3],r[4],r[5],r[6])
- def write(self,out,lib):
- conn = db.connect(out)
- curs = conn.cursor()
- curs.executescript(emptydb)
- for c in lib.getAuthorCodes():
- curs.execute("insert into author(code,surname,name) values('%s','%s','%s')"%(
- str(c),
- lib.getAuthorSurname(c),
- lib.getAuthorName(c)))
- for c in lib.getStudioCodes():
- curs.execute("insert into studio(code,name,website,country) values('%s','%s','%s','%s')"%(
- str(c),
- lib.getStudioName(c),
- lib.getStudioWebsite(c),
- lib.getStudioCountry(c)))
- for c in lib.getAnimationCodes():
- curs.execute("insert into animation(author,studio,name,code,zhanr,year,episode) values('%s','%s','%s','%s','%s','%s','%s')"%(
- str(lib.getAnimationAuthorCode(c)),
- str(lib.getAnimationStudioCode(c)),
- lib.getAnimationName(c),
- str(c),
- lib.getAnimationZhanr(c),
- str(lib.getAnimationYear(c)),
- str(lib.getAnimationEpisode(c))))
- conn.commit()
- conn.close()
- lib2 = library()
- dat1 = dataxml()
- dat2 = datasql()
- dat1.read("old.xml", lib2)
- dat2.write("new.sqlite", lib2)
- lib2.clear()
- dat2.read("new.sqlite", lib2)
- dat1.write("temp.xml", lib2)
- print(lib2.getAnimationCodes())
- for s in lib2.getAnimationCodes():
- print (lib2.getAll(s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement