gen_schedule.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. # Quick and dirty script for generating a random MapSchedule.xml
  3. import datetime
  4. import random
  5. import sys
  6. import json
  7. from xml.dom import minidom
  8. MAPS = ['FRANCE', 'INNSBRUCK', 'LONDON', 'MAKURIISLANDS', 'RICHMOND', 'SCOTLAND']
  9. dom = minidom.parseString('<MapSchedule><appointments></appointments><VERSION>1</VERSION></MapSchedule>')
  10. appts = dom.getElementsByTagName('appointments')[0]
  11. now = datetime.datetime.now(datetime.timezone.utc).replace(day=1)
  12. prev_map = None
  13. for i in range(0, 500):
  14. map_choice = random.choice(MAPS)
  15. while map_choice == prev_map:
  16. map_choice = random.choice(MAPS)
  17. prev_map = map_choice
  18. appt = dom.createElement('appointment')
  19. appt.setAttribute('map', map_choice)
  20. appt.setAttribute('start', now.strftime("%Y-%m-%dT00:01-04"))
  21. appts.appendChild(appt)
  22. now += datetime.timedelta(days=2)
  23. with open('MapSchedule_v2.xml', 'w') as f:
  24. f.write(dom.toprettyxml())
  25. with open('../data/climbs.txt') as f:
  26. data = json.load(f)
  27. CLIMBS = [x['road'] for x in data]
  28. dom = minidom.parseString('<PortalRoads><PortalRoadSchedule><appointments></appointments><VERSION>1</VERSION></PortalRoadSchedule></PortalRoads>')
  29. appts = dom.getElementsByTagName('appointments')[0]
  30. now = datetime.datetime.now(datetime.timezone.utc)
  31. prev_climb = None
  32. for i in range(0, 100):
  33. climb_choice = random.choice(CLIMBS)
  34. while climb_choice == prev_climb:
  35. climb_choice = random.choice(CLIMBS)
  36. prev_climb = climb_choice
  37. appt = dom.createElement('appointment')
  38. appt.setAttribute('road', climb_choice)
  39. appt.setAttribute('portal', '0')
  40. appt.setAttribute('start', now.strftime("%Y-%m-%dT00:01-04"))
  41. appts.appendChild(appt)
  42. now += datetime.timedelta(days=2)
  43. with open('PortalRoadSchedule_v1.xml', 'w') as f:
  44. f.write(dom.toprettyxml())