Skip to content

Commit

Permalink
parseJson.py: Ignore certain WZ JSON file types
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 30, 2024
1 parent 7ff1ae8 commit ce77812
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions po/scripts/parseJson.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import json, sys, re

IGNORED_WZ_JSON_FILE_TYPES = {'wz2100.proxmsgs.v1', 'wz2100.briefs.v1'}

def printString(s, begin, end, filename, jsonPath):
if not re.match(r'^(\*.*\*|CAM[0-9] .*|Z ?NULL.*)$', s):
sys.stdout.write('{}{}) // SRC: {}: {}{}'.format(begin, json.dumps(s, ensure_ascii=False), filename, jsonPath, end))

def parse(obj, filename, jsonPath="$"):
def parse(obj, filename):
def _parse(obj, filename, jsonPath="$"):
if isinstance(obj, dict):
for k, v in obj.items():
_parse(v, filename, jsonPath + "." + k)
if k in ['name', 'tip', 'easy_tip', 'medium_tip', 'hard_tip', 'insane_tip'] and isinstance(v, str):
printString(v, '_(', '\n', filename, jsonPath + "." + k)
elif k in ['text', 'ranks'] and isinstance(v, list):
for idx, s in enumerate(v):
itemPath = jsonPath + "." + k + "[" + str(idx) + "]"
if isinstance(s, str):
if k == 'text':
printString(s, '_(', '\n', filename, itemPath)
elif k == 'ranks':
printString(s, 'NP_("rank", ', '\n', filename, itemPath)
elif isinstance(obj, list):
for idx, v in enumerate(obj):
_parse(v, filename, jsonPath + "[" + str(idx) + "]")

if isinstance(obj, dict):
for k, v in obj.items():
parse(v, filename, jsonPath + "." + k)
if k in ['name', 'tip', 'easy_tip', 'medium_tip', 'hard_tip', 'insane_tip'] and isinstance(v, str):
printString(v, '_(', '\n', filename, jsonPath + "." + k)
elif k in ['text', 'ranks'] and isinstance(v, list):
for idx, s in enumerate(v):
itemPath = jsonPath + "." + k + "[" + str(idx) + "]"
if isinstance(s, str):
if k == 'text':
printString(s, '_(', '\n', filename, itemPath)
elif k == 'ranks':
printString(s, 'NP_("rank", ', '\n', filename, itemPath)
elif isinstance(obj, list):
for idx, v in enumerate(obj):
parse(v, filename, jsonPath + "[" + str(idx) + "]")
# check for json format types that should be ignored
if 'type' in obj:
if obj['type'] in IGNORED_WZ_JSON_FILE_TYPES:
#sys.stderr.write('// IGNORING: {}\n'.format(filename))
return

_parse(obj, filename);

parse(json.load(open(sys.argv[1], 'r')), sys.argv[1])

0 comments on commit ce77812

Please sign in to comment.