gen_schedule.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. from dateutil.relativedelta import relativedelta
  9. MAPS = ['FRANCE', 'INNSBRUCK', 'LONDON', 'MAKURIISLANDS', 'RICHMOND', 'SCOTLAND']
  10. dom = minidom.parseString('<MapSchedule><appointments></appointments><VERSION>1</VERSION></MapSchedule>')
  11. appts = dom.getElementsByTagName('appointments')[0]
  12. now = datetime.datetime.now(datetime.timezone.utc).replace(day=1)
  13. maps_loop = []
  14. prev_map = None
  15. for _ in range(0, 200):
  16. if not maps_loop:
  17. maps_loop = list(MAPS)
  18. random.shuffle(maps_loop)
  19. map_choice = maps_loop.pop()
  20. while map_choice == prev_map:
  21. map_choice = random.choice(MAPS)
  22. prev_map = map_choice
  23. appt = dom.createElement('appointment')
  24. appt.setAttribute('map', map_choice)
  25. appt.setAttribute('start', now.strftime("%Y-%m-%dT00:01-04"))
  26. appts.appendChild(appt)
  27. now += datetime.timedelta(days=2)
  28. with open('MapSchedule_v2.xml', 'w') as f:
  29. f.write(dom.toprettyxml())
  30. with open('../data/climbs.txt') as f:
  31. data = json.load(f)
  32. CLIMBS = [x['road'] for x in data]
  33. dom = minidom.parseString('<PortalRoads><PortalRoadSchedule><appointments></appointments><VERSION>1</VERSION></PortalRoadSchedule></PortalRoads>')
  34. appts = dom.getElementsByTagName('appointments')[0]
  35. month = datetime.datetime.now(datetime.timezone.utc).replace(day=1)
  36. climbs_loop = []
  37. climbs_loop_month = []
  38. prev_climb = None
  39. prev_climb_month = None
  40. for _ in range(0, 13):
  41. if not climbs_loop_month:
  42. climbs_loop_month = list(CLIMBS)
  43. random.shuffle(climbs_loop_month)
  44. climb_choice_month = climbs_loop_month.pop()
  45. while climb_choice_month == prev_climb_month:
  46. climb_choice_month = random.choice(CLIMBS)
  47. prev_climb_month = climb_choice_month
  48. appt = dom.createElement('appointment')
  49. appt.setAttribute('road', climb_choice_month)
  50. appt.setAttribute('world', '10')
  51. appt.setAttribute('portal_of_month', 'true')
  52. appt.setAttribute('portal', '0')
  53. appt.setAttribute('start', month.strftime("%Y-%m-%dT00:01-04"))
  54. appts.appendChild(appt)
  55. day = month
  56. month += relativedelta(months=+1)
  57. for _ in range(0, 10):
  58. if not climbs_loop:
  59. climbs_loop = list(CLIMBS)
  60. random.shuffle(climbs_loop)
  61. climb_choice = climbs_loop.pop()
  62. while climb_choice == prev_climb or climb_choice == climb_choice_month:
  63. climb_choice = random.choice(CLIMBS)
  64. prev_climb = climb_choice
  65. appt = dom.createElement('appointment')
  66. appt.setAttribute('road', climb_choice)
  67. appt.setAttribute('world', '1')
  68. appt.setAttribute('portal', '0')
  69. appt.setAttribute('start', day.strftime("%Y-%m-%dT00:01-04"))
  70. appts.appendChild(appt)
  71. day += datetime.timedelta(days=3)
  72. with open('PortalRoadSchedule_v1.xml', 'w') as f:
  73. f.write(dom.toprettyxml())