-
-
Save radamhu/2f4c0c2156f3e467d754dcf5b70b27ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from typing import List | |
def run(args: List[str]): | |
filename = args[0] | |
with open(filename, "r") as f: | |
data = json.loads(f.read()) | |
original_entries = data['items'] | |
# Find duplicates in the bitwarden password export file | |
# Duplicate entries have the same "name" and "login.username" fields | |
unique_entries = {} | |
duplicates = [] | |
for entry in original_entries: | |
name = entry["name"] | |
username = entry["login"]["username"] | |
entry_id = f"{username}@{name}" | |
if entry_id in unique_entries: | |
duplicates.append(entry) | |
else: | |
unique_entries[entry_id] = entry | |
# Convert unique_entries back to a list | |
# Convert unique_entries and duplicates to bitwarden format | |
# Write to file | |
unique_entries = list(unique_entries.values()) | |
def to_bitwarden_format(entries: List[dict]): | |
return {"encrypted": False, "items": entries, "folders": []} | |
mapped_unique_entries = to_bitwarden_format(unique_entries) | |
mapped_duplicates = to_bitwarden_format(duplicates) | |
with open("bitwarden-unique.json", "w") as f: | |
f.write(json.dumps(mapped_unique_entries, indent=2)) | |
with open("bitwarden-duplicates.json", "w") as f: | |
f.write(json.dumps(mapped_duplicates, indent=2)) | |
if __name__ == "__main__": | |
import sys | |
run(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment