get_climbs.py 966 B

123456789101112131415161718192021222324252627
  1. import os
  2. import xml.etree.ElementTree as ET
  3. import json
  4. import subprocess
  5. data = []
  6. subprocess.run(['wad_unpack.exe', 'C:\\Program Files (x86)\\Zwift\\assets\\Worlds\\roads.wad'])
  7. climbs = 'Worlds\\portal'
  8. for file in os.listdir(climbs):
  9. if file.startswith('road_'):
  10. tree = ET.parse(os.path.join(climbs, file))
  11. metadata = tree.find('.//metadata')
  12. name = metadata.find('m_PortalRoadUserFacingName').text
  13. length = round(float(metadata.find('m_PortalRoadCourseLength').text) / 100000, 1)
  14. if length.is_integer():
  15. length = int(length)
  16. ascent = int(float(metadata.find('m_PortalRoadCourseAscentF').text) / 100)
  17. climb = {
  18. 'name': '%s (%s km / %s m)' % (name, length, ascent),
  19. 'road': metadata.find('m_PortalRoadHash').text
  20. }
  21. data.append(climb)
  22. with open('../data/climbs.txt', 'w') as f:
  23. json.dump(sorted(data, key=lambda row: row['name']), f, indent=2)