File: //tmp/fix_aqua.py
import json, re, sys
raw = open('/tmp/aq_orig.json', encoding='utf-8').read().strip()
fixed = re.sub(r'\\u([0-9a-fA-F]{4})', lambda m: chr(int(m.group(1),16)), raw)
try:
data = json.loads(fixed)
except Exception as e:
sys.stderr.write("parse fixed failed: %s\n" % e)
data = json.loads(raw)
cnt=0
def walk(els):
global cnt
for e in els:
if isinstance(e,dict):
if e.get('widgetType','').startswith('tpg'):
e.setdefault('settings',{})['order']='DESC'
e['settings']['orderby']='date'
cnt+=1
walk(e.get('elements',[]))
walk(data)
out = json.dumps(data, ensure_ascii=True, separators=(',',':'))
open('/tmp/aq_clean.json','w').write(out)
bs_u = chr(92)+'u'
print("widgetow z order=DESC:", cnt)
print("rozmiar wyniku:", len(out))
print("liczba escape sekwencji:", out.count(bs_u))
print("zawiera Atrakcje:", "Atrakcje" in out)