Skip to content

Instantly share code, notes, and snippets.

@amPerl
Last active November 11, 2016 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amPerl/5fe6ccdc5d11e17945ad2f6c9da8b4f4 to your computer and use it in GitHub Desktop.
Save amPerl/5fe6ccdc5d11e17945ad2f6c9da8b4f4 to your computer and use it in GitHub Desktop.
tool to convert Drift City's VehicleUpgrade.xlt into json for easier parsing
import argparse
import os
import json
from collections import defaultdict
def convert(xlt_path, json_path):
xlt = None
with open(xlt_path, 'rb') as f:
xlt = f.read().decode('utf-16').split('\r\n')
cols = [col.replace(' ', '_').lower() for col in xlt[2].split('\t')]
cars = defaultdict(list)
for line in xlt[3:]:
line_split = line.split('\t')
if len(line_split) < 2:
continue
car_sort = int(line_split[1])
line_obj = {}
for i, val in enumerate(line_split):
col_name = cols[i]
if not len(col_name):
continue
line_obj[col_name] = val.split('\0')[0].rstrip()
cars[car_sort].append(line_obj)
with open(json_path, 'w') as f:
f.write(json.dumps(cars, indent=2))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('xlt', help="path to the xlt file")
parser.add_argument('json', help="json output file")
args = parser.parse_args()
convert(args.xlt, args.json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment