variants_to_json.py 734 B

1234567891011121314151617181920212223
  1. import json
  2. import sys
  3. sys.path.insert(0, '../protobuf')
  4. import variants_pb2
  5. from google.protobuf.json_format import MessageToDict
  6. with open("variant", "rb") as f:
  7. variants = variants_pb2.FeatureResponse()
  8. variants.ParseFromString(f.read())
  9. keep = ['zwift_launcher_', 'game_1_26_event_survey']
  10. with open("../data/variants.txt") as f:
  11. vs = [d for d in json.load(f)['variants'] if any(d['name'].startswith(s) for s in keep)]
  12. for v in MessageToDict(variants)['variants']:
  13. if 'fields' in v['values']:
  14. v['values']['fields'] = dict(sorted(v['values']['fields'].items()))
  15. vs.append(v)
  16. with open("../data/variants.txt", "w") as f:
  17. json.dump({'variants': sorted(vs, key=lambda x: x['name'])}, f, indent=2)