16def write_xml(configDictionary = {}, pagesLocationList = [], location = str()):
17 document = minidom.Document()
18 root = document.createElement(
"comet")
19 root.setAttribute(
"xmlns:comet",
"http://www.denvog.com/comet/")
20 root.setAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance")
21 root.setAttribute(
"xsi:schemaLocation",
"http://www.denvog.com http://www.denvog.com/comet/comet.xsd")
22 document.appendChild(root)
24 title = document.createElement(
"title")
25 if "title" in configDictionary.keys():
26 title.appendChild(document.createTextNode(str(configDictionary[
"title"])))
28 title.appendChild(document.createTextNode(str(
"Untitled Comic")))
29 root.appendChild(title)
30 description = document.createElement(
"description")
31 if "summary" in configDictionary.keys():
32 description.appendChild(document.createTextNode(str(configDictionary[
"summary"])))
34 description.appendChild(document.createTextNode(str(
"There was no summary upon generation of this file.")))
35 root.appendChild(description)
36 if "seriesName" in configDictionary.keys():
37 series = document.createElement(
"series")
38 series.appendChild(document.createTextNode(str(configDictionary[
"seriesName"])))
39 root.appendChild(series)
40 if "seriesNumber" in configDictionary.keys():
41 issue = document.createElement(
"issue")
42 issue.appendChild(document.createTextNode(str(configDictionary[
"seriesNumber"])))
43 root.appendChild(issue)
44 if "seriesVolume" in configDictionary.keys():
45 volume = document.createElement(
"volume")
46 volume.appendChild(document.createTextNode(str(configDictionary[
"seriesVolume"])))
47 root.appendChild(volume)
49 if "publisherName" in configDictionary.keys():
50 publisher = document.createElement(
"publisher")
51 publisher.appendChild(document.createTextNode(str(configDictionary[
"publisherName"])))
52 root.appendChild(publisher)
54 if "publishingDate" in configDictionary.keys():
55 date = document.createElement(
"date")
56 date.appendChild(document.createTextNode(str(configDictionary[
"publishingDate"])))
57 root.appendChild(date)
59 if "genre" in configDictionary.keys():
60 genreListConf = configDictionary[
"genre"]
61 if isinstance(configDictionary[
"genre"], dict):
62 genreListConf = configDictionary[
"genre"].keys()
63 for genreE
in genreListConf:
64 genre = document.createElement(
"genre")
65 genre.appendChild(document.createTextNode(str(genreE)))
66 root.appendChild(genre)
68 if "characters" in configDictionary.keys():
69 for char
in configDictionary[
"characters"]:
70 character = document.createElement(
"character")
71 character.appendChild(document.createTextNode(str(char)))
72 root.appendChild(character)
74 if "format" in configDictionary.keys():
75 format = document.createElement(
"format")
76 format.appendChild(document.createTextNode(str(
",".join(configDictionary[
"format"]))))
77 root.appendChild(format)
79 if "language" in configDictionary.keys():
80 language = document.createElement(
"language")
81 language.appendChild(document.createTextNode(str(configDictionary[
"language"])))
82 root.appendChild(language)
83 if "rating" in configDictionary.keys():
84 rating = document.createElement(
"rating")
85 rating.appendChild(document.createTextNode(str(configDictionary[
"rating"])))
86 root.appendChild(rating)
88 if "pages" in configDictionary.keys():
89 pages = document.createElement(
"pages")
90 pages.appendChild(document.createTextNode(str(len(configDictionary[
"pages"]))))
91 root.appendChild(pages)
93 if "isbn-number" in configDictionary.keys():
94 identifier = document.createElement(
"identifier")
95 identifier.appendChild(document.createTextNode(str(configDictionary[
"isbn-number"])))
96 root.appendChild(identifier)
98 if "authorList" in configDictionary.keys():
99 for authorE
in range(len(configDictionary[
"authorList"])):
100 author = document.createElement(
"creator")
101 authorDict = configDictionary[
"authorList"][authorE]
102 if "role" in authorDict.keys():
103 if str(authorDict[
"role"]).lower()
in [
"writer",
"penciller",
"editor",
"assistant editor",
"cover artist",
"letterer",
"inker",
"colorist"]:
104 if str(authorDict[
"role"]).lower() ==
"cover artist":
105 author = document.createElement(
"coverDesigner")
106 elif str(authorDict[
"role"]).lower() ==
"assistant editor":
107 author = document.createElement(
"editor")
109 author = document.createElement(str(authorDict[
"role"]).lower())
111 if "last-name" in authorDict.keys():
112 stringName.append(authorDict[
"last-name"])
113 if "first-name" in authorDict.keys():
114 stringName.append(authorDict[
"first-name"])
115 if "nickname" in authorDict.keys():
116 stringName.append(
"(" + authorDict[
"nickname"] +
")")
117 author.appendChild(document.createTextNode(str(
",".join(stringName))))
118 root.appendChild(author)
120 if "pages" in configDictionary.keys():
121 if "cover" in configDictionary.keys():
123 pageList = configDictionary[
"pages"]
124 coverNumber = pageList.index(configDictionary[
"cover"])
125 if len(pagesLocationList) >= coverNumber:
126 coverImage = document.createElement(
"coverImage")
127 coverImage.appendChild(document.createTextNode(str(os.path.basename(pagesLocationList[coverNumber]))))
128 root.appendChild(coverImage)
129 readingDirection = document.createElement(
"readingDirection")
130 readingDirection.appendChild(document.createTextNode(str(
"ltr")))
131 if "readingDirection" in configDictionary.keys():
132 if configDictionary[
"readingDirection"] ==
"rightToLeft":
133 readingDirection.appendChild(document.createTextNode(str(
"rtl")))
134 root.appendChild(readingDirection)
136 f = open(location,
'w', newline=
"", encoding=
"utf-8")
137 f.write(document.toprettyxml(indent=
" "))