import os import xml.etree.ElementTree as ET import re import json import subprocess worlds = 'C:\\Program Files (x86)\\Zwift\\assets\\Worlds' world_to_course = { '1': (6, 'Watopia'), '2': (2, 'Richmond'), '3': (7, 'London'), '4': (8, 'New York'), '5': (9, 'Innsbruck'), '6': (10, 'Bologna'), '7': (11, 'Yorkshire'), '8': (12, 'Crit City'), '9': (13, 'Makuri Islands'), '10': (14, 'France'), '11': (15, 'Paris'), '12': (16, 'Gravel Mountain'), '13': (17, 'Scotland') } data = [] for directory in os.listdir(worlds): world = directory[5:] if os.path.isdir(os.path.join(worlds, directory)) and world in world_to_course: subprocess.run(['wad_unpack.exe', os.path.join(worlds, directory, 'data_1.wad')]) routes = os.path.join('Worlds', directory, 'routes') for file in os.listdir(routes): with open(os.path.join(routes, file)) as f: xml = f.read() tree = ET.fromstring(re.sub(r"(<\?xml[^>]+\?>)", r"\1", xml) + "") route = tree.find('route') if route.get('eventOnly') == '1': event = { 'name': '%s - %s' % (world_to_course[world][1], route.get('name').strip()), 'route': int(route.get('nameHash')), 'course': world_to_course[world][0], 'sport': 1 if route.get('sportType') == '2' else 0 } data.append(event) with open('../data/events.txt', 'w') as f: json.dump(sorted(data, key=lambda row: row['name']), f, indent=2)