Skip to content

Instantly share code, notes, and snippets.

@ATouhou
Forked from jalaziz/dedupe.py
Created June 16, 2017 18:52
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 ATouhou/ee0b78f2fc251bb8dbe61cc33d477822 to your computer and use it in GitHub Desktop.
Save ATouhou/ee0b78f2fc251bb8dbe61cc33d477822 to your computer and use it in GitHub Desktop.
Tabs Outliner Deduplication
import json
import os
export_file = 'tree-exported-Sat-Apr-09-2016.tree'
backup_export_file = '{}.bak'.format(export_file)
new_tree = []
seen_urls = set()
os.rename(export_file, backup_export_file)
with open(backup_export_file) as f:
tree = json.load(f)
for node in reversed(tree):
if isinstance(node, list):
item = node[1]
if ('type' not in item) or (item['type'] == 'tab'):
url = item['data']['url']
if url in seen_urls:
print 'skipping duplicate: {}'.format(url)
continue
seen_urls.add(url)
new_tree.append(node)
new_tree = list(reversed(new_tree))
window_count = -1
tab_count = -1
for node in new_tree:
if isinstance(node, list):
item = node[1]
pos = []
if item.get('type') in ('win', 'savedwin'):
window_count += 1
tab_count = -1
pos = [window_count]
else:
tab_count += 1
pos = [window_count, tab_count]
node[2] = pos
with open(export_file, 'w') as f:
json.dump(new_tree, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment