Created
August 12, 2014 09:34
-
-
Save k5trismegistus/9182652b6142715b9956 to your computer and use it in GitHub Desktop.
ComicInfo.xmlの情報を取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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