Skip to content

Commit

Permalink
Update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Nov 23, 2023
1 parent c585472 commit 054ad11
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion scripts/bot_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import sys
import csv
sys.path.append(os.path.join(sys.path[0], 'protobuf')) # otherwise import in .proto does not work
sys.path.insert(0, '../protobuf')
import profile_pb2
import udp_node_msgs_pb2

Expand Down
2 changes: 1 addition & 1 deletion scripts/get_game_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def main(argv):
session = requests.session()
access_token, refresh_token, expired_in = post_credentials(session, username, password)
game_info = get_game_info(session, access_token).decode('utf-8')
with open('game_info.txt', 'wb') as f:
with open('../game_info.txt', 'wb') as f:
f.write(game_info.encode('utf-8-sig'))

logout(session, refresh_token)
Expand Down
2 changes: 1 addition & 1 deletion scripts/upload_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import os
import requests
import sys
sys.path.append(os.path.join(sys.path[0], 'protobuf')) # otherwise import in .proto does not work
sys.path.insert(0, '../protobuf')
import activity_pb2
import profile_pb2

Expand Down
29 changes: 10 additions & 19 deletions scripts/variants_to_json.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
import json
import protobuf.variants_pb2 as variants_pb2
import sys
sys.path.insert(0, '../protobuf')
import variants_pb2
from google.protobuf.json_format import MessageToDict

variants = variants_pb2.FeatureResponse()

with open("variant", "rb") as f:
variants = variants_pb2.FeatureResponse()
variants.ParseFromString(f.read())

vs = []

with open("variants.txt") as f:
j = json.load(f)
vs = j['variants']
with open("../variants.txt") as f:
vs = json.load(f)['variants']

for variant in variants.variants:
d = MessageToDict(variant)
v = {}
v['name'] = d['name']
if 'value' in d:
v['value'] = d['value']
d['values'] = dict(d['values'])
for f in d['values']:
d['values'][f] = dict(sorted(d['values'][f].items()))
v['values'] = d['values']
for v in MessageToDict(variants)['variants']:
if 'fields' in v['values']:
v['values']['fields'] = dict(sorted(v['values']['fields'].items()))
vs[:] = [d for d in vs if d.get('name') != v['name']]
vs.append(v)

with open("variants.txt", "w") as f:
with open("../variants.txt", "w") as f:
json.dump({'variants': sorted(vs, key=lambda x: x['name'])}, f, indent=2)

0 comments on commit 054ad11

Please sign in to comment.