From f49c2dedf61f62fec0dceb73012c2d8a1de6390a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 19 May 2020 15:29:50 +1000 Subject: [PATCH] Add script for converting compatibility XML to CSV --- scripts/compatibility_xml_to_csv.py | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 scripts/compatibility_xml_to_csv.py diff --git a/scripts/compatibility_xml_to_csv.py b/scripts/compatibility_xml_to_csv.py new file mode 100644 index 000000000..33835f865 --- /dev/null +++ b/scripts/compatibility_xml_to_csv.py @@ -0,0 +1,56 @@ +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() + +