aboutsummaryrefslogtreecommitdiffhomepage
path: root/model_renamer.py
blob: 24c41b9c6f9655d015f7213da881c7466ce36e0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# This script will take the ModelRepo.xml file and rename the models based on the trademark

import argparse
import xml.etree.ElementTree as ET

parser = argparse.ArgumentParser(description='Rename the models in an XML file')
parser.add_argument('--original', metavar='xml_file', type=str, help='The XML file to be parsed')
parser.add_argument('--out', metavar='output_file', type=str, default='ModelRepo_generated.xml', help='The output file', const='ModelRepo_generated.xml', nargs='?')
args = parser.parse_args()

tree = ET.parse(args.original)
root = tree.getroot()

def get_actual_model(model):
    name = model.get('name')
    trademark = model.get('tm')

    # Remove "Based on " from the name
    new_name = trademark.replace('Based on ', '')
    # remove "®" from the name
    new_name = new_name.replace('®', '')
    # Change out the word "loaded" for "|"
    new_name = new_name.replace('loaded with', '|')
    # remove the word "with" from "loaded with"
    new_name = new_name.replace('with', '|')

    # Check if the name contains a Mono or Stereo suffix
    if name.endswith('(M)'):
        new_name += ' (M)'
    elif name.endswith('(S)'):
        new_name += ' (S)'

    return new_name


print('Renaming models in file: ' + args.original)
# Itterate over the categories inside the XML file
for category in root.findall('Category'):
    # Itterate over the models inside the category
    for model in category.findall('Model'):
        # First check if the model has a trademark
        trademark = model.get('tm')
        if trademark != "" and trademark != None:
            new_name = get_actual_model(model)
            model.set('name', new_name)

print('Saving file to: ' + args.out)
# Save the XML file
tree.write(args.out, encoding='UTF-8', xml_declaration=True)