Skip to content

Instantly share code, notes, and snippets.

@rotespferd
Last active April 10, 2021 16:36
Show Gist options
  • Save rotespferd/5d4418b7879cca6a9a5f2dfbe5647eb4 to your computer and use it in GitHub Desktop.
Save rotespferd/5d4418b7879cca6a9a5f2dfbe5647eb4 to your computer and use it in GitHub Desktop.
Convert OOTP team_nick_names.txt to XML
from xml.dom import minidom
import os
txtFile = open("./team_nick_names.txt", "r")
nicknameLines = txtFile.readlines()
root = minidom.Document()
root.encoding = "utf-8"
xml = root.createElement("TEAM_NICK_NAMES")
root.appendChild(xml)
for line in nicknameLines:
tnn = root.createElement("TNN")
so = root.createElement("SO")
so_text = root.createTextNode(line.strip())
so.appendChild(so_text)
st_kr = root.createElement("ST_KR")
st_kr_text = root.createTextNode("na")
st_kr.appendChild(st_kr_text)
tnn.appendChild(so)
tnn.appendChild(st_kr)
xml.appendChild(tnn)
# save xml file
xml_filename = "team_nick_names.xml"
with open(xml_filename, "w") as f:
f.write(root.toprettyxml(indent ="\t"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment