1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| import json from collections import OrderedDict
SRC_DIR = 'oridumpdata' OUT_DIR = 'tabdata'
src_cfgs = [ ('179log.json', 'stateMigratedToIDB', False), ('179ldb.json', 'state', False), ('pydumper.json', 'stateMigratedToIDB', False), ('LevelDBDumper.json', 'stateMigratedToIDB', True), ]
def load_source(sname, key, double_unescape): with open(f'{SRC_DIR}/{sname}') as f: d = json.load(f) if double_unescape: raw = d[0]['data'][key] raw = json.loads(raw) else: raw = d[key] return json.loads(raw)
all_sources = [cfg[0] for cfg in src_cfgs]
groups_merged = OrderedDict()
for sname, key, double in src_cfgs: data = load_source(sname, key, double) for g in data['tabGroups']: gid = g['id'] if gid not in groups_merged: groups_merged[gid] = { 'id': gid, 'createDate': g['createDate'], 'label': g.get('label'), 'sources': set(), 'tabs': OrderedDict(), } gm = groups_merged[gid] gm['sources'].add(sname) for t in g['tabsMeta']: url = t['url'] if url not in gm['tabs']: gm['tabs'][url] = { 'url': url, 'title': t['title'], 'sources': set(), } gm['tabs'][url]['sources'].add(sname)
other3 = {'179log.json', 'pydumper.json', 'LevelDBDumper.json'}
merged_output = [] diff_ldb_only = [] diff_ldb_missing = [] diff_others = []
for gid, gm in groups_merged.items(): merged_tabs = [] tabs_ldb_only = [] tabs_ldb_missing = [] tabs_others = [] for url, tab in gm['tabs'].items(): src_list = sorted(tab['sources']) merged_tabs.append({ 'url': url, 'title': tab['title'], 'sources': src_list, }) ss = tab['sources'] if ss == {'179ldb.json'}: tabs_ldb_only.append({ 'url': url, 'title': tab['title'], 'present_in': sorted(ss), 'missing_from': sorted(other3), }) elif '179ldb.json' not in ss: missing = [s for s in all_sources if s not in ss] tabs_ldb_missing.append({ 'url': url, 'title': tab['title'], 'present_in': sorted(ss), 'missing_from': missing, }) elif ss & other3 and len(ss & other3) < 3: present = sorted(ss & other3) missing = sorted(other3 - ss) tabs_others.append({ 'url': url, 'title': tab['title'], 'present_in_others': present, 'missing_from_others': missing, 'also_in_ldb': '179ldb.json' in ss, }) merged_output.append({ 'id': gid, 'createDate': gm['createDate'], 'label': gm['label'], 'tabs': merged_tabs, }) def maybe_append(dst, tabs): if tabs: dst.append({ 'id': gid, 'createDate': gm['createDate'], 'label': gm['label'], 'tabs': tabs, }) maybe_append(diff_ldb_only, tabs_ldb_only) maybe_append(diff_ldb_missing, tabs_ldb_missing) maybe_append(diff_others, tabs_others)
for sname, key, double in src_cfgs: data = load_source(sname, key, double) base = sname.replace('.json', '') base = base.replace('LevelDBDumper', 'levaldumper') outname = f'{base}-tab.json' with open(f'{OUT_DIR}/{outname}', 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=2)
with open(f'{OUT_DIR}/merged.json', 'w', encoding='utf-8') as f: json.dump(merged_output, f, ensure_ascii=False, indent=2) with open(f'{OUT_DIR}/diff-179ldb-only.json', 'w', encoding='utf-8') as f: json.dump(diff_ldb_only, f, ensure_ascii=False, indent=2) with open(f'{OUT_DIR}/diff-179ldb-missing.json', 'w', encoding='utf-8') as f: json.dump(diff_ldb_missing, f, ensure_ascii=False, indent=2) with open(f'{OUT_DIR}/diff-others.json', 'w', encoding='utf-8') as f: json.dump(diff_others, f, ensure_ascii=False, indent=2)
total_tabs = sum(len(g['tabs']) for g in merged_output) n1 = sum(len(g['tabs']) for g in diff_ldb_only) n2 = sum(len(g['tabs']) for g in diff_ldb_missing) n3 = sum(len(g['tabs']) for g in diff_others) print(f"merged: {len(merged_output)} groups, {total_tabs} tabs") print(f"diff-179ldb-only: {len(diff_ldb_only)} groups, {n1} tabs") print(f"diff-179ldb-missing: {len(diff_ldb_missing)} groups, {n2} tabs") print(f"diff-others: {len(diff_others)} groups, {n3} tabs") print("done")
|