Skip to content

Instantly share code, notes, and snippets.

@BenderV
Created November 17, 2022 08:13
Show Gist options
  • Save BenderV/0bb9bb0324a387b37cd9a1e2d2cb0ebf to your computer and use it in GitHub Desktop.
Save BenderV/0bb9bb0324a387b37cd9a1e2d2cb0ebf to your computer and use it in GitHub Desktop.
"""
Small tool to deduplicate 1password items
"""
import json
import os
def hash_dict(dic):
return str(hash(frozenset(dic.items())))
def mkhash(item):
return item['title'] + hash_dict(item['vault']) + str(hash(item.get('additional_information')))
os.system("op item list --format json > passwords.json")
with open('passwords.json', 'r') as f:
data = json.loads(f.read())
imap = {}
duplicates = []
for row in data:
if mkhash(row) in imap:
print(row['id'], row['title'])
os.system(f"op item delete {row['id']}")
continue
imap[mkhash(row)] = row['id']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment