From 8c971b044d69ff6310c709e0a1ab5bf17262e014 Mon Sep 17 00:00:00 2001 From: Frederik Baerentsen Date: Tue, 7 Jun 2022 21:59:03 +0200 Subject: [PATCH] fixed zip issue (#1) --- docker-compose.yml | 2 +- main.py | 53 +++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 728c06f..e2a7201 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,5 +7,5 @@ services: ports: - '5000:5000' volumes: - - '/opt/data/Comics/ComicRack/Oni Press:/library:ro' + - '/opt/data/Comics/ComicRack:/library:ro' - '${PWD}/:/app' diff --git a/main.py b/main.py index dc68855..c118287 100644 --- a/main.py +++ b/main.py @@ -45,34 +45,35 @@ def import2sql(): for file in files: f = os.path.join(root, file) #try: - try: - s = zipfile.ZipFile(f) - #s = gzip.GzipFile(f) - Bs_data = BeautifulSoup(s.open('ComicInfo.xml').read(), "xml") - #print(Bs_data.select('Series')[0].text, file=sys.stderr) - #print(Bs_data.select('Title')[0].text, file=sys.stderr) - CVDB=re.findall('(?<=\[CVDB)(.*)(?=].)', Bs_data.select('Notes')[0].text) - #list.append('CVDB'+CVDB[0] + ': ' + Bs_data.select('Series')[0].text + "(" + Bs_data.select('Volume')[0].text + ") : " + Bs_data.select('Number')[0].text ) - #print(list, file=sys.stdout) - - ISSUE=Bs_data.select('Number')[0].text - SERIES=Bs_data.select('Series')[0].text - VOLUME=Bs_data.select('Volume')[0].text - PUBLISHER=Bs_data.select('Publisher')[0].text + if f.endswith('.cbz'): try: - TITLE=Bs_data.select('Title')[0].text + s = zipfile.ZipFile(f) + #s = gzip.GzipFile(f) + Bs_data = BeautifulSoup(s.open('ComicInfo.xml').read(), "xml") + #print(Bs_data.select('Series')[0].text, file=sys.stderr) + #print(Bs_data.select('Title')[0].text, file=sys.stderr) + CVDB=re.findall('(?<=\[CVDB)(.*)(?=].)', Bs_data.select('Notes')[0].text) + #list.append('CVDB'+CVDB[0] + ': ' + Bs_data.select('Series')[0].text + "(" + Bs_data.select('Volume')[0].text + ") : " + Bs_data.select('Number')[0].text ) + #print(list, file=sys.stdout) + + ISSUE=Bs_data.select('Number')[0].text + SERIES=Bs_data.select('Series')[0].text + VOLUME=Bs_data.select('Volume')[0].text + PUBLISHER=Bs_data.select('Publisher')[0].text + try: + TITLE=Bs_data.select('Title')[0].text + except: + TITLE="" #sometimes title is blank. + PATH=f + UPDATED=str(datetime.datetime.now()) + #print(UPDATED,file=sys.stdout) + #sql="INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES ("+CVDB[0]+",'"+ISSUE+"','"+SERIES+"','"+VOLUME+"','"+PUBLISHER+"','"+TITLE+"','"+file+"','" + f + "','" + UPDATED + "')" + #print(sql,file=sys.stdout) + #conn.execute(sql); + conn.execute("INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES (?,?,?,?,?,?,?,?,?)", (CVDB[0], ISSUE, SERIES, VOLUME, PUBLISHER, TITLE, file, f, UPDATED)) + conn.commit() except: - TITLE="" #sometimes title is blank. - PATH=f - UPDATED=str(datetime.datetime.now()) - #print(UPDATED,file=sys.stdout) - #sql="INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES ("+CVDB[0]+",'"+ISSUE+"','"+SERIES+"','"+VOLUME+"','"+PUBLISHER+"','"+TITLE+"','"+file+"','" + f + "','" + UPDATED + "')" - #print(sql,file=sys.stdout) - #conn.execute(sql); - conn.execute("INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES (?,?,?,?,?,?,?,?,?)", (CVDB[0], ISSUE, SERIES, VOLUME, PUBLISHER, TITLE, file, f, UPDATED)) - conn.commit() - except: - print(f,file=sys.stdout) + print(f,file=sys.stdout) conn.close() elapsed = timeit.default_timer() - start_time