43def write_xml(configDictionary = {}, pagesLocationList = [], location = str()):
44 document = minidom.Document()
45 root = document.createElement(
"ComicInfo")
46 root.setAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance")
47 root.setAttribute(
"xmlns:xsd",
"http://www.w3.org/2001/XMLSchema")
49 title = document.createElement(
"Title")
50 if "title" in configDictionary.keys():
51 title.appendChild(document.createTextNode(str(configDictionary[
"title"])))
53 title.appendChild(document.createTextNode(str(
"Untitled Comic")))
54 root.appendChild(title)
55 description = document.createElement(
"Summary")
56 if "summary" in configDictionary.keys():
57 description.appendChild(document.createTextNode(str(configDictionary[
"summary"])))
59 description.appendChild(document.createTextNode(str(
"There was no summary upon generation of this file.")))
60 root.appendChild(description)
62 if "seriesNumber" in configDictionary.keys():
63 number = document.createElement(
"Number")
64 number.appendChild(document.createTextNode(str(configDictionary[
"seriesNumber"])))
65 root.appendChild(number)
66 if "seriesName" in configDictionary.keys():
67 seriesname = document.createElement(
"Series")
68 seriesname.appendChild(document.createTextNode(str(configDictionary[
"seriesName"])))
69 root.appendChild(seriesname)
71 if "publishingDate" in configDictionary.keys():
72 date = QDate.fromString(configDictionary[
"publishingDate"], Qt.DateFormat.ISODate)
73 publishYear = document.createElement(
"Year")
74 publishYear.appendChild(document.createTextNode(str(date.year())))
75 publishMonth = document.createElement(
"Month")
76 publishMonth.appendChild(document.createTextNode(str(date.month())))
77 publishDay = document.createElement(
"Day")
78 publishDay.appendChild(document.createTextNode(str(date.day())))
79 root.appendChild(publishYear)
80 root.appendChild(publishMonth)
81 root.appendChild(publishDay)
83 if "format" in configDictionary.keys():
84 for form
in configDictionary[
"format"]:
85 formattag = document.createElement(
"Format")
86 formattag.appendChild(document.createTextNode(str(form)))
87 root.appendChild(formattag)
88 if "otherKeywords" in configDictionary.keys():
89 tags = document.createElement(
"Tags")
90 tags.appendChild(document.createTextNode(str(
", ".join(configDictionary[
"otherKeywords"]))))
91 root.appendChild(tags)
93 if "authorList" in configDictionary.keys():
94 for authorE
in range(len(configDictionary[
"authorList"])):
95 author = document.createElement(
"Writer")
96 authorDict = configDictionary[
"authorList"][authorE]
97 if "role" in authorDict.keys():
98 if str(authorDict[
"role"]).lower()
in [
"writer",
"penciller",
"editor",
"assistant editor",
"cover artist",
"letterer",
"inker",
"colorist"]:
99 if str(authorDict[
"role"]).lower() ==
"cover artist":
100 author = document.createElement(
"CoverArtist")
101 elif str(authorDict[
"role"]).lower() ==
"assistant editor":
102 author = document.createElement(
"Editor")
104 author = document.createElement(str(authorDict[
"role"]).title())
106 if "last-name" in authorDict.keys():
107 stringName.append(authorDict[
"last-name"])
108 if "first-name" in authorDict.keys():
109 stringName.append(authorDict[
"first-name"])
110 if "nickname" in authorDict.keys():
111 stringName.append(
"(" + authorDict[
"nickname"] +
")")
112 author.appendChild(document.createTextNode(str(
",".join(stringName))))
113 root.appendChild(author)
114 if "publisherName" in configDictionary.keys():
115 publisher = document.createElement(
"Publisher")
116 publisher.appendChild(document.createTextNode(str(configDictionary[
"publisherName"])))
117 root.appendChild(publisher)
119 if "genre" in configDictionary.keys():
120 genreListConf = configDictionary[
"genre"]
121 if isinstance(configDictionary[
"genre"], dict):
122 genreListConf = configDictionary[
"genre"].keys()
123 for genreE
in genreListConf:
124 genre = document.createElement(
"Genre")
125 genre.appendChild(document.createTextNode(str(genreE)))
126 root.appendChild(genre)
127 blackAndWhite = document.createElement(
"BlackAndWhite")
128 blackAndWhite.appendChild(document.createTextNode(str(
"No")))
129 root.appendChild(blackAndWhite)
130 readingDirection = document.createElement(
"Manga")
131 readingDirection.appendChild(document.createTextNode(str(
"No")))
132 if "readingDirection" in configDictionary.keys():
133 if configDictionary[
"readingDirection"] ==
"rightToLeft":
134 readingDirection.appendChild(document.createTextNode(str(
"YesAndRightToLeft")))
135 root.appendChild(readingDirection)
137 if "characters" in configDictionary.keys():
138 for char
in configDictionary[
"characters"]:
139 character = document.createElement(
"Character")
140 character.appendChild(document.createTextNode(str(char)))
141 root.appendChild(character)
142 if "pages" in configDictionary.keys():
143 pagecount = document.createElement(
"PageCount")
144 pagecount.appendChild(document.createTextNode(str(len(configDictionary[
"pages"]))))
145 root.appendChild(pagecount)
146 pages = document.createElement(
"Pages")
148 if "pages" in configDictionary.keys()
and "cover" in configDictionary.keys():
149 covernumber = configDictionary[
"pages"].index(configDictionary[
"cover"])
150 for i
in range(len(pagesLocationList)):
151 page = document.createElement(
"Page")
152 page.setAttribute(
"Image", str(i))
154 page.setAttribute(
"Type",
"FrontCover")
155 pages.appendChild(page)
156 root.appendChild(pages)
157 document.appendChild(root)
158 f = open(location,
'w', newline=
"", encoding=
"utf-8")
159 f.write(document.toprettyxml(indent=
" "))