Created
February 24, 2022 02:55
-
-
Save schwa/2ec8a1aa80392d9b75744f829065d573 to your computer and use it in GitHub Desktop.
Python script to help import 1Password data into iCloudKeychain
This file contains 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
# Filter1Password.py | |
# Quick script to help filter records from a 1Password .csv export for importing into Safari/iCloud Keychain | |
# Safari rejects records with no username, password or url. This script takes your 1Password export and "splits" it | |
# into two CSV file, one with these records filtered out, and one with just records with the required fields. You can then import the | |
# filtered .csv file directly into Safari and should not get import warnings. | |
# This script also filters out records with the "Archive" field set to true - these are 1Password records that you previously Trashed | |
import csv | |
from pathlib import Path | |
import urllib | |
missing_data = [] | |
filtered = [] | |
path = Path("1PasswordExport.csv") | |
reader = csv.DictReader(path.open()) | |
for record in reader: | |
if record["Archived"] == "true": | |
print("Skipping record (archived)") | |
continue | |
# Uncomment this to reduce the website url to just the domain. | |
# url = record["Url"] | |
# parts = urllib.parse.urlparse(url) | |
# domain = parts.netloc | |
# record["Url"] = domain | |
if not record["Username"] or not record["Password"] or not record["Url"]: | |
print("Skipping record (no username, password or url") | |
missing_data.append(record) | |
continue | |
filtered.append(record) | |
path = Path("1PasswordExport-Filtered.csv") | |
writer = csv.DictWriter(path.open("w"), reader.fieldnames) | |
writer.writeheader() | |
writer.writerows(filtered) | |
path = Path("1PasswordExport-MissingData.csv") | |
writer = csv.DictWriter(path.open("w"), reader.fieldnames) | |
writer.writeheader() | |
writer.writerows(missing_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment