Skip to content

Instantly share code, notes, and snippets.

@k5trismegistus
Created August 12, 2014 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k5trismegistus/9182652b6142715b9956 to your computer and use it in GitHub Desktop.
Save k5trismegistus/9182652b6142715b9956 to your computer and use it in GitHub Desktop.
ComicInfo.xmlの情報を取得
import zipfile
import xml.etree.ElementTree as etree
class ComicInfoXmlHandler():
def __init__(self):
self.series = ''
self.number = ''
self.title = ''
self.circle = ''
self.member = ''
self.genre = ''
self.year = ''
self.month = ''
self.day = ''
self.fromxml = ['Series', 'Number', 'Title', 'Writer', 'Penciller', 'Genre', 'Year', 'Month', 'Day']
self.todisplay = [self.series, self.number, self.title, self.circle, self.member, self.genre, self.year, self.month, self.day]
def get_info(self, filepath):
with zipfile.ZipFile(filepath, mode='r',) as z:
comicinfoxml = z.open('ComicInfo.xml', mode='r')
infoTree = etree.parse(comicinfoxml)
root = infoTree.getroot()
for i in range(len(self.fromxml)):
self.todisplay[i] = root.findtext(self.fromxml[i])
for i in range(len(self.todisplay)):
print(self.todisplay[i])
if __name__ == '__main__':
cix = ComicInfoXmlHandler()
cix.get_info(r'path/to/archive.cbz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment