working on comicdb.xml import
This commit is contained in:
parent
9c797eeddb
commit
a04b119ce5
114
db.py
114
db.py
@ -5,51 +5,113 @@ import re
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
def createdb():
|
def createdb():
|
||||||
print(1)
|
|
||||||
conn = sqlite3.connect('../test_database.db')
|
conn = sqlite3.connect('../test_database.db')
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS comics
|
CREATE TABLE IF NOT EXISTS comics
|
||||||
(
|
(
|
||||||
[book_id] TEXT PRIMARY KEY,
|
[book_id] TEXT PRIMARY KEY,
|
||||||
[book_path] TEXT,
|
[book_path] TEXT,
|
||||||
[series] TEXT,
|
[series] TEXT,
|
||||||
[number] TEXT,
|
[seriesgroup] TEXT,
|
||||||
[count] INTEGER,
|
[number] TEXT,
|
||||||
[volume] TEXT,
|
[count] INTEGER,
|
||||||
[seriesgroup] TEXT,
|
[volume] TEXT,
|
||||||
[notes] TEXT,
|
[notes] TEXT,
|
||||||
[year] INTEGER,
|
[year] INTEGER,
|
||||||
[month] INTEGER,
|
[month] INTEGER,
|
||||||
[day] INTEGER
|
[day] INTEGER,
|
||||||
)
|
[writer] TEXT,
|
||||||
|
[penciller] TEXT,
|
||||||
|
[inker] TEXT,
|
||||||
|
[letterer] TEXT,
|
||||||
|
[colorist] TEXT,
|
||||||
|
[coverartist] TEXT,
|
||||||
|
[publisher] TEXT,
|
||||||
|
[genre] TEXT,
|
||||||
|
[pagecount] INTEGER,
|
||||||
|
[languageiso] TEXT,
|
||||||
|
[scaninformation] TEXT,
|
||||||
|
[pages] INTEGER,
|
||||||
|
[added] TEXT,
|
||||||
|
[filesize] INTEGER,
|
||||||
|
[filemodifiedtime] TEXT,
|
||||||
|
[filecreationtime] TEXT
|
||||||
|
)
|
||||||
''')
|
''')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def dropdb():
|
def dropdb():
|
||||||
conn = sqlite3.connect('../test_database.db')
|
conn = sqlite3.connect('../test_database.db')
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute('DROP TABLE COMICS')
|
c.execute('DROP TABLE COMICS')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
def checkempty(v,t):
|
||||||
|
r=""
|
||||||
|
try:
|
||||||
|
r=v.find(t).text
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return r
|
||||||
|
|
||||||
def loaddata():
|
def loaddata():
|
||||||
count = 0
|
conn = sqlite3.connect('../test_database.db')
|
||||||
book_id,book_path,series,number="","","",""
|
c = conn.cursor()
|
||||||
|
|
||||||
|
book_id,book_path,series,seriesgroup,number="","","","",""
|
||||||
count=0
|
count=0
|
||||||
volume,seriesgroup,notes="","",""
|
volume,seriesgroup,notes="","",""
|
||||||
year,month,date=0,0,0
|
year,month,day=0,0,0
|
||||||
|
writer,penciller,inker,letterer,colorist,coverartist,publiser,genre="","","","","","","",""
|
||||||
|
pagecount=0
|
||||||
|
languageiso,scaninformation="",""
|
||||||
|
pages=0
|
||||||
|
added=""
|
||||||
|
filesize=0
|
||||||
|
filemodificationtime,filecreationtime="",""
|
||||||
|
|
||||||
tree = ET.parse('../ComicDb_small.xml')
|
tree = ET.parse('../ComicDb_small.xml')
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
for child in root:
|
for child in root:
|
||||||
print(child.tag,child.attrib)
|
#print("child: ", child.tag,child.attrib)
|
||||||
if child.tag == 'Books':
|
if child.tag == 'Books':
|
||||||
for grandchild in child:
|
for grandchild in child:
|
||||||
print(grandchild.tag,grandchild.attrib)
|
#print("grandchild: ",grandchild.tag,grandchild.attrib)
|
||||||
for ggchild in grandchild:
|
#print(grandchild.attrib)
|
||||||
print(ggchild.tag,ggchild.attrib)
|
#print(type(grandchild.attrib))
|
||||||
|
book_id=grandchild.attrib['Id']
|
||||||
|
book_path=grandchild.attrib['File']
|
||||||
|
#for i,j in grandchild.attrib.items():
|
||||||
|
# print(i,j)
|
||||||
|
# #print(i,i["Id"])
|
||||||
|
#series=grandchild.attrib['Series'].text
|
||||||
|
#print(series)
|
||||||
|
#print(grandchild[0].tag)
|
||||||
|
#series=grandchild.find('Series').text
|
||||||
|
series=checkempty(grandchild,'Series')
|
||||||
|
number=checkempty(grandchild,'Number')
|
||||||
|
count=checkempty(grandchild,'Count')
|
||||||
|
seriesgroup=checkempty(grandchild,'SeriesGroup')
|
||||||
|
notes=checkempty(grandchild,'Notes')
|
||||||
|
year=checkempty(grandchild,'Year')
|
||||||
|
month=checkempty(grandchild,'Month')
|
||||||
|
day=checkempty(grandchild,'Day')
|
||||||
|
writer=checkempty(grandchild,'Writer')
|
||||||
|
penciller=checkempty(grandchild,'Penciller')
|
||||||
|
inker=checkempty(grandchild,'Inker')
|
||||||
|
letterer=checkempty(grandchild,'Letterer')
|
||||||
|
|
||||||
|
c.execute("INSERT OR REPLACE INTO COMICS (book_id,book_path,series,number,count,seriesgroup,notes,year,month,day,writer,penciller, inker,letterer) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",(book_id,book_path,series,number,count,seriesgroup,notes,year,month,day,writer,penciller,inker,letterer))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
#for ggchild in grandchild:
|
||||||
|
# print(ggchild.tag)
|
||||||
|
# print(ggchild.text)
|
||||||
|
#print("----")
|
||||||
|
|
||||||
#for books in child.findall('Book'):
|
#for books in child.findall('Book'):
|
||||||
#print(books,type(books))
|
#print(books,type(books))
|
||||||
#print(books.tag, books.attrib)
|
#print(books.tag, books.attrib)
|
||||||
@ -73,4 +135,8 @@ def loaddata():
|
|||||||
# series=i.select('Series')[0].text
|
# series=i.select('Series')[0].text
|
||||||
# except:
|
# except:
|
||||||
# pass
|
# pass
|
||||||
|
#dropdb()
|
||||||
|
#createdb()
|
||||||
|
|
||||||
loaddata()
|
loaddata()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user