57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
|
import sys
|
||
|
import argparse
|
||
|
import xml.etree.ElementTree as ET
|
||
|
|
||
|
|
||
|
def convert_list(filename, separator=','):
|
||
|
fields = ["Game Code", "Game Title", "Region", "Compatibility", "Upscaling Issues", "Version tested", "Comments"]
|
||
|
output = separator.join(fields) + "\n"
|
||
|
|
||
|
tree = ET.parse(filename)
|
||
|
for child in tree.getroot():
|
||
|
if (child.tag != "entry"):
|
||
|
print("!!! Skipping invalid tag '%s'" % child.tag)
|
||
|
continue
|
||
|
|
||
|
game_code = child.get("code") or ""
|
||
|
game_title = child.get("title") or ""
|
||
|
region = child.get("region") or ""
|
||
|
|
||
|
node = child.find("compatibility")
|
||
|
compatibility = node.text if node is not None else ""
|
||
|
node = child.find("upscaling-issues")
|
||
|
upscaling_issues = node.text if node is not None else ""
|
||
|
node = child.find("version-tested")
|
||
|
version_tested = node.text if node is not None else ""
|
||
|
node = child.find("comments")
|
||
|
comments = node.text if node is not None else ""
|
||
|
|
||
|
fix = None
|
||
|
if separator == '\t':
|
||
|
fix = lambda x: x.replace('\t', ' ')
|
||
|
elif separator == ',':
|
||
|
fix = lambda x: x if x.find(',') < 0 else ("\"%s\"" % x)
|
||
|
else:
|
||
|
fix = lambda x: x
|
||
|
|
||
|
entry_fields = [fix(game_code), fix(game_title), fix(region), fix(compatibility), fix(upscaling_issues), fix(version_tested), fix(comments)]
|
||
|
output += separator.join(entry_fields) + "\n"
|
||
|
|
||
|
return output
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
parser = argparse.ArgumentParser()
|
||
|
parser.add_argument("--tabs", action="store_true")
|
||
|
parser.add_argument("list_file", action="store")
|
||
|
parser.add_argument("output_file", action="store")
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
output = convert_list(args.list_file, '\t' if args.tabs else ',')
|
||
|
output_file = open(args.output_file, "w")
|
||
|
output_file.write(output)
|
||
|
output_file.close()
|
||
|
|
||
|
|