Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.16 KB | None | 0 0
  1. import os,xml.dom.minidom
  2. class general:
  3. def __init__(self, code=0):
  4. self.__code=code
  5. def setCode(self, value): self.__code=value
  6. def getCode(self):return self.__code
  7. class namee:
  8. def __init__(self, name=''):
  9. self.__name=name
  10. def setName(self, value): self.__name=value
  11. def getName(self):return self.__name
  12.  
  13.  
  14. class author(namee, general):
  15. def __init__ (self,code=0, surname='', name=''):
  16. general.__init__(self, code)
  17. namee.__init__(self, name)
  18. self.__surname = surname
  19. def setSurname(self, value): self.__surname=value
  20. def getSurname(self):return self.__surname
  21. def getAuthor(self):
  22. s1="%s %s" % (self.getSurname(), self.getName())
  23. return s1
  24. Author1=author(surname='Ishigami', name='Oda', code=2)
  25. Author2=author(surname='Masashi', name='Kimoto', code=3)
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. class studio(namee, general):
  35. def __init__(self, code=0, name='', website='', country=''):
  36. namee.__init__(self, name)
  37. general.__init__(self, code)
  38. self.__website = website
  39. self.__country = country
  40. self.__name = name
  41. def getWebsite(self):return self.__website
  42. def getName(self):return self.__name
  43. def getCountry(self):return self.__country
  44. def getStudio(self):
  45. s5="%s %s %s" % (self.getName(), self.getCountry(), self.getWebsite())
  46. return s5
  47. Studio1=studio('Toei Animation',2, 'http://www.toei-anim.co.jp/', 'China')
  48. Studio2=studio('Studio Pierrot',3, 'pierrot.jp', 'Japan')
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. class animation(namee, general):
  56. def __init__ (self, author=None, studio=None ,name='', code=0, zhanr='', year=0, episode=0):
  57. namee.__init__(self, name)
  58. general.__init__(self, code)
  59. self.__author = author
  60. self.__studio = studio
  61. self.__zhanr = zhanr
  62. self.__year = year
  63. self.__episode = episode
  64. def setZhanr(self, value): self.__zhanr=value
  65. def getZhanr(self):return self.__zhanr
  66. def setYear(self, value): self.__year=value
  67. def getYear(self):return self.__year
  68. def setEpisode(self, value): self.__episode=value
  69. def getEpisode(self):return self.__episode
  70. def getAuthorCode(self):
  71. if self.__author:return self.__author.getCode()
  72.  
  73. def getStudioCode(self):
  74. if self.__studio:return self.__studio.getCode()
  75. def getAnimation(self):
  76. s = "%s %s %s %s %s %s" % (self.__author.getAuthor(),self.__studio.getStudio(), self.getName(), self.getZhanr(), self.getYear(), self.getEpisode())
  77. return s
  78.  
  79.  
  80.  
  81.  
  82. class generalList:
  83. def __init__(self):self.__list=[]
  84. def clear(self):self.__list=[]
  85. def findByCode(self,code):
  86. for l in self.__list:
  87. if l.getCode()==code:
  88. return l
  89. break
  90. def getCodes(self):return [s.getCode() for s in self.__list]
  91. def appendList(self,value):self.__list.append(value)
  92. def removeList(self,code):
  93. for s in self.__list:
  94. if s.getCode()==code:self.__list.remove(s)
  95. def getName(self,code):return self.findByCode(code).getName()
  96.  
  97.  
  98.  
  99. class authorList(generalList):
  100. def getSurname(self,code):return self.findByCode(code).getSurname()
  101. def getName(self,code):return self.findByCode(code).getName()
  102. def getAuthorList(self, code):
  103. s3="%s %s" % (self.findByCode(code).getSurname(), self.findByCode(code).getName())
  104. return s3
  105.  
  106.  
  107. class studioList(generalList):
  108. def getWebsite(self,code):return self.findByCode(code).getWebsite()
  109. def getName(self,code):return self.findByCode(code).getName()
  110. def getCountry(self,code):return self.findByCode(code).getCountry()
  111. def getStudioList(self,code):
  112. s5="%s %s %s" % (self.findByCode(code).getName(), self.findByCode(code).getCountry(), self.findByCode(code).getWebsite())
  113. return s5
  114.  
  115. class animationList(generalList):
  116. def getZhanr(self,code):return self.findByCode(code).getZhanr()
  117. def getEpisode(self,code):return self.findByCode(code).getEpisode()
  118. def getYear(self, code):return self.findByCode(code).getYear()
  119. def getName(self,code):return self.findByCode(code).getName()
  120. def getAnimationList(self, code):
  121. s13="%s %s %s %s" % (self.findByCode(code).getName(), self.findByCode(code).getZhanr(), self.findByCode(code).getEpisode(), self.findByCode(code).getYear())
  122. return s13
  123.  
  124. class generalListEdit(generalList):
  125. def getNewCode(self):
  126. m=0
  127. for c in self.getCodes():
  128. if c>m:m=c
  129. return m+1
  130. def setName(self,code,value):return self.findByCode(code).setName(value)
  131. class AuthorListEdit(authorList,generalListEdit):
  132. def newRec(self,code=0,surname='',name=''):self.appendList(author(code,surname,name))
  133. def setSurname(self,code,value):self.findByCode(code).setSurname(value)
  134. def setName(self,code,value):self.findByCode(code).setName(value)
  135. def removeAuthor(self,code):self.__Authors.removeList(code)
  136.  
  137. class StudioListEdit(studioList,generalListEdit):
  138. def newRec(self,code=0,name='',website='',country=''):self.appendList(studio(code, name, website,country))
  139. def setWebsite(self,code,value):self.findByCode(code).setWebsite(value)
  140. def setCountry(self,code,value):self.findByCode(code).setCountry(value)
  141. def setName(self,code,value):self.findByCode(code).setName(value)
  142.  
  143. class AnimationListEdit(animationList,generalListEdit):
  144. def newRec(self,author, studio ,name='', code=0, zhanr='', year=0, episode=0):
  145. self.appendList(animation(author, studio ,name, code, zhanr, year, episode))
  146. def setAuthor(self,code,value):self.findByCode(code).setAuthor(value)
  147.  
  148. def setStudio(self,code,value):self.findByCode(code).setStudio(value)
  149. def setZhanr(self,code,value):self.findByCode(code).setZhanr(value)
  150. def setYear(self,code,value):self.findByCode(code).setYear(value)
  151. def setEpisode(self,code,value):self.findByCode(code).setEpisode(value)
  152. def getZhanr(self,code):return self.findByCode(code).getZhanr()
  153. def getYear(self,code):return self.findByCode(code).getYear()
  154. def getEpisode(self,code):return self.findByCode(code).getEpisode()
  155. def getAuthorCode(self,code):return self.findByCode(code).getAuthorCode()
  156. def getAuthorSurname(self,code):return self.findByCode(code).getAuthorSurname()
  157. def getAuthorName(self,code):return self.findByCode(code).getAuthorName()
  158.  
  159. def getStudioCode(self,code):return self.findByCode(code).getStudioCode()
  160.  
  161.  
  162. def getStudioName(self,code):return self.findByCode(code).getStudioName()
  163. def getStudioWebsite(self,code):return self.findByCode(code).getStudioWebsite()
  164. def getStudioCountry(self,code):return self.findByCode(code).getStudioCountry()
  165.  
  166. class library:
  167. def __init__(self):
  168. self.__Animations=AnimationListEdit()
  169. self.__Studios=StudioListEdit()
  170. self.__Authors=AuthorListEdit()
  171. def removeAuthor(self,code):
  172. self.__Authors.removeList(code)
  173. def removeStudio(self,code):
  174. self.__Studios.removeList(code)
  175.  
  176.  
  177.  
  178. def clear(self):
  179. self.__Animations.clear()
  180. self.__Authors.clear()
  181. self.__Studios.clear()
  182.  
  183. def newAuthor(self,code=0,surname='',name=''):self.__Authors.newRec(code,surname,name)
  184. def findAuthorByCode(self,code):return self.__Authors.findByCode(code)
  185. def getAuthorNewCode(self):return self.__Authors.getNewCode()
  186. def getAuthorCodes(self):return self.__Authors.getCodes()
  187. def getAuthorName(self,code):return self.__Authors.getName(code)
  188. def getAuthorSurname(self,code):return self.__Authors.getSurname(code)
  189. def setAuthorName(self,code,value):self.__Authors.setName(code,value)
  190. def setAuthorSurname(self,code,value):self.__Authors.setSurname(code,value)
  191.  
  192. def newStudio(self,code=0,name='',website='',country=''):self.__Studios.newRec(code, name, website, country)
  193. def findStudioByCode(self,code):return self.__Studios.findByCode(code)
  194. def getStudioNewCode(self):return self.__Studios.getNewCode()
  195. def getStudioCodes(self):return self.__Studios.getCodes()
  196. def getStudioCountry(self,code):return self.__Studios.getCountry(code)
  197. def getStudioWebsite(self,code):return self.__Studios.getWebsite(code)
  198. def getStudioName(self,code):return self.__Studios.getName(code)
  199. def setStudioCountry(self,code,value):self.__Studios.setCountry(code,value)
  200. def setStudioWebsite(self,code,value):self.__Studios.setWebsite(code,value)
  201. def setStudioName(self,code,value):self.__Studios.setName(code,value)
  202.  
  203. def removeAnimation(self,code):self.__Animations.removeList(code)
  204. def getAnimationNewCode(self):return self.__Animations.getNewCode()
  205. def removeAnimation(self,code):self.__Animations.removeList(code)
  206. def newAnimation(self,author, studio ,name='', code=0, zhanr='', year=0, episode=0):self.__Animations.newRec(author, studio ,name, code, zhanr, year, episode)
  207. def findAnimationByCode(self,code):return self.__Animation.findByCode(code)
  208. def setAnimationZhanr(self,code,value):self.__Animations.setZhanr(code,value)
  209. def setAnimationYear(self,code,value):self.__Animations.setYear(code,value)
  210. def setAnimationEpisode(self,code,value):self.__Animations.setEpisode(code,value)
  211. def setAnimationName(self,code,value):self.__Animations.setName(code,value)
  212. def setAnimationAuthor(self,code,pcode):self.__Animations.setAuthor(code, self.findAnimationByCode(pcode))
  213. def getAnimationZhanr(self,code):return self.__Animations.getZhanr(code)
  214. def getAnimationName(self,code):return self.__Animations.getName(code)
  215. def getAnimationYear(self,code):return self.__Animations.getYear(code)
  216. def getAnimationEpisode(self,code):return self.__Animations.getEpisode(code)
  217. def getAnimationAuthorCode(self,code):return self.__Animations.getAuthorCode(code)
  218. def getAnimationAuthorName(self,code):return self.__Animations.getAuthorName(code)
  219. def getAnimationAuthorSurname(self, code):return self.__Animations.getAuthorSurname(code)
  220. def getAnimationStudioName(self,code):return self.__Animations.getStudioName(code)
  221. def getAnimationStudioCountry(self,code):return self.__Animations.getStudioCountry(code)
  222. def getAnimationStudioWebsite(self,code):return self.__Animations.getWebsite(code)
  223. def getAnimationStudioCode(self,code):return self.__Animations.getStudioCode(code)
  224. def findAnimationByCode(self,code):return self.__Animations.findByCode(code)
  225. def getAnimationNewCode(self):return self.__Animations.getNewCode()
  226. def getAnimationCodes(self):return self.__Animations.getCodes()
  227. def getAll(self, code):
  228. s10="%s %s %s" % (self.__Authors.getAuthorList(code),self.__Studios.getStudioList(code), self.__Animations.getAnimationList(code))
  229. return s10
  230.  
  231.  
  232. Studio1=studio(name='utofable', code=1, website='wewewe.com', country='Japan')
  233. Author1=author(code=1,name='Suzuki', surname='Kyoshitsu')
  234. Animation1=animation(code=1, author=Author1, studio=Studio1,year=1980,zhanr='Senen',name='naruto',episode=200)
  235.  
  236. l1=AuthorListEdit()
  237. l1.appendList(Author1)
  238. print(Animation1.getAuthorCode())
  239. l2=StudioListEdit()
  240. l2.appendList(Studio1)
  241.  
  242. l3=AnimationListEdit()
  243. l3.appendList(Animation1)
  244.  
  245. f1=library()
  246. f1.newAuthor(1, 'Suzuki', 'Kyoshitsu')
  247. print(f1.findAuthorByCode(1).getAuthor())
  248.  
  249. f1.newStudio(1,'utofable','wewewe.com','Japan')
  250. print(f1.findStudioByCode(1).getStudio())
  251.  
  252. f1.newAnimation (f1.findAuthorByCode(1),f1.findStudioByCode(1),'naruto',1,'Senen',1980,200)
  253. print(f1.findAnimationByCode(1).getAnimation())
  254. print(f1.getAnimationAuthorCode(1))
  255. print(f1.getAnimationCodes())
  256.  
  257. print(f1.getAll(1))
  258.  
  259.  
  260. class dataxml:
  261. def read(self,inp,lib):
  262. dom=xml.dom.minidom.parse(inp)
  263. dom.normalize()
  264. for node in dom.childNodes[0].childNodes:
  265. if (node.nodeType==node.ELEMENT_NODE)and(node.nodeName=='author'):
  266. code,surname,name=0,"",""
  267. for t in node.attributes.items():
  268. if t[0]=="code":code=int(t[1])
  269. if t[0]=="name":name=t[1]
  270. if t[0]=="surname":surname=t[1]
  271. lib.newAuthor(code,surname,name)
  272. if (node.nodeType==node.ELEMENT_NODE)and(node.nodeName=='studio'):
  273. code,name, website, country=0,"","",""
  274. for t in node.attributes.items():
  275. if t[0]=="code":code=int(t[1])
  276. if t[0]=="name":name=t[1]
  277. if t[0]=="website":website=t[1]
  278. if t[0]=="country":country=t[1]
  279. lib.newStudio(code,name,website, country)
  280. if (node.nodeType==node.ELEMENT_NODE)and(node.nodeName=='animation'):
  281. author, studio, name, code, zhanr, year,episode=None,None,"",0,"",0,0
  282. for t in node.attributes.items():
  283. if t[0]=="author":author=lib.findAuthorByCode(int(t[1]))
  284. if t[0]=="studio":studio=lib.findStudioByCode(int(t[1]))
  285. if t[0]=="name":name=t[1]
  286. if t[0]=="code":code=int(t[1])
  287. if t[0]=="zhanr":zhanr=t[1]
  288. if t[0]=="year":year=int(t[1])
  289. if t[0]=="episode":episode=int(t[1])
  290. lib.newAnimation(author, studio, name, code, zhanr, year,episode)
  291. for n in node.childNodes:
  292. if (n.nodeType == n.ELEMENT_NODE)and(n.nodeName == "author"):
  293. for t in n.attributes.items():
  294. if t[0] == "code": author = sh.findAuthorByCode(int(t[1]))
  295. sh.appendAnimationAuthor(code, customer)
  296. for n in node.childNodes:
  297. if (n.nodeType == n.ELEMENT_NODE) and (n.nodeName == "studio"):
  298. for t in n.attributes.items():
  299. if t[0] == "code": studio = sh.findStudioByCode(int(t[1]))
  300. sh.appendAnimationStudio(code, product)
  301. def write(self,out,lib):
  302. dom=xml.dom.minidom.Document()
  303. root=dom.createElement("library")
  304. dom.appendChild(root)
  305. for c in lib.getAuthorCodes():
  306. aut=dom.createElement("author")
  307. aut.setAttribute('code',str(c))
  308. aut.setAttribute('surname',lib.getAuthorSurname(c))
  309. aut.setAttribute('name',lib.getAuthorName(c))
  310. root.appendChild(aut)
  311. for c in lib.getStudioCodes():
  312. stud=dom.createElement("studio")
  313. stud.setAttribute('name',lib.getStudioName(c))
  314. stud.setAttribute('code',str(c))
  315. stud.setAttribute('website',lib.getStudioWebsite(c))
  316. stud.setAttribute('country',lib.getStudioCountry(c))
  317. root.appendChild(stud)
  318.  
  319. for c in lib.getAnimationCodes():
  320. anim=dom.createElement("animation")
  321. aut=dom.createElement("author")
  322. aut.setAttribute('code',str(lib.getAnimationAuthorCode(c)))
  323. stud=dom.createElement("studio")
  324. stud.setAttribute('code',str(lib.getAnimationStudioCode(c)))
  325. anim.setAttribute('name',lib.getAnimationName(c))
  326. anim.setAttribute('code',str(c))
  327. anim.setAttribute('zhanr',lib.getAnimationZhanr(c))
  328. anim.setAttribute('year',str(lib.getAnimationYear(c)))
  329. anim.setAttribute('episode',str(lib.getAnimationEpisode(c)))
  330. anim.appendChild(aut)
  331. anim.appendChild(stud)
  332. root.appendChild(anim)
  333.  
  334. f = open(out,"wb")
  335. f.write(dom.toprettyxml(encoding='utf-8'))
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343. import os
  344. import sqlite3 as db
  345.  
  346. emptydb = """
  347. PRAGMA foreign_keys = ON;
  348.  
  349. create table author
  350. (code integer primary key,
  351. surname text,
  352. name text);
  353.  
  354. create table studio
  355. (code integer primary key,
  356. name text,
  357. website text,
  358. country text);
  359.  
  360. create table animation
  361. (author integer references author(code) on update cascade on delete set null,
  362. studio integer references studio(code) on update cascade on delete set null,
  363. code integer primary key,
  364. name text,
  365. zhanr text,
  366. year integer,
  367. episode integer);
  368. """
  369. class datasql:
  370. def read(self,inp,lib):
  371. conn = db.connect(inp)
  372. curs = conn.cursor()
  373.  
  374. curs.execute('select code,surname,name from author')
  375. data=curs.fetchall()
  376. for r in data:lib.newAuthor(r[0],r[1],r[2])
  377.  
  378. curs.execute('select code,name, website, country from studio')
  379. data=curs.fetchall()
  380. for r in data:lib.newStudio(r[0],r[1],r[2],r[3])
  381.  
  382. curs.execute('select author, studio, name, code, zhanr, year,episode from animation')
  383. data=curs.fetchall()
  384. for r in data:lib.newAnimation(lib.findAuthorByCode(r[0]),lib.findStudioByCode(r[1]),r[2],r[3],r[4],r[5],r[6])
  385. def write(self,out,lib):
  386. conn = db.connect(out)
  387. curs = conn.cursor()
  388. curs.executescript(emptydb)
  389.  
  390. for c in lib.getAuthorCodes():
  391. curs.execute("insert into author(code,surname,name) values('%s','%s','%s')"%(
  392. str(c),
  393. lib.getAuthorSurname(c),
  394. lib.getAuthorName(c)))
  395. for c in lib.getStudioCodes():
  396. curs.execute("insert into studio(code,name,website,country) values('%s','%s','%s','%s')"%(
  397. str(c),
  398. lib.getStudioName(c),
  399. lib.getStudioWebsite(c),
  400. lib.getStudioCountry(c)))
  401. for c in lib.getAnimationCodes():
  402. curs.execute("insert into animation(author,studio,name,code,zhanr,year,episode) values('%s','%s','%s','%s','%s','%s','%s')"%(
  403. str(lib.getAnimationAuthorCode(c)),
  404. str(lib.getAnimationStudioCode(c)),
  405. lib.getAnimationName(c),
  406. str(c),
  407. lib.getAnimationZhanr(c),
  408. str(lib.getAnimationYear(c)),
  409. str(lib.getAnimationEpisode(c))))
  410. conn.commit()
  411. conn.close()
  412.  
  413.  
  414. lib2 = library()
  415. dat1 = dataxml()
  416. dat2 = datasql()
  417. dat1.read("old.xml", lib2)
  418. dat2.write("new.sqlite", lib2)
  419. lib2.clear()
  420. dat2.read("new.sqlite", lib2)
  421. dat1.write("temp.xml", lib2)
  422. print(lib2.getAnimationCodes())
  423. for s in lib2.getAnimationCodes():
  424. print (lib2.getAll(s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement