Created
December 9, 2021 17:10
-
-
Save tyhenry/a0f6d92d41c081eddf874a05f670d540 to your computer and use it in GitHub Desktop.
Convert 1password export file (.1pux archive -> export.data) to CSV format
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 csv | |
import json | |
import os | |
def convert(file_in, dir_out=""): | |
with open(file_in, 'r', encoding='utf8') as json_file: | |
data = json.load(json_file) | |
for account in data["accounts"]: | |
print(f"Processing account: {account['attrs']['name']}") | |
for vault in account["vaults"]: | |
vault_name = vault["attrs"]["name"] | |
print(f"Processing vault: {vault_name}") | |
csv_dir = dir_out if dir_out != "" else os.path.dirname(file_in) | |
with open(os.path.join(csv_dir, f"{vault_name}.csv"), "w", newline='', encoding='utf8') as csv_file: | |
writer = csv.writer(csv_file) | |
writer.writerow(["Title", "URL", "Username", "Password"]) | |
for item in vault["items"]: | |
item = item["item"] | |
overview = item["overview"] | |
title = overview["title"] | |
url = overview["url"] | |
print(f"Processing item: {title}") | |
username, password = None, None | |
for field in item["details"]["loginFields"]: | |
if "designation" not in field: | |
continue | |
if field["designation"] == "username": | |
username = field["value"] | |
if field["designation"] == "password": | |
password = field["value"] | |
writer.writerow([title, url, username, password]) | |
if __name__ == "__main__": | |
import argparse | |
parser = argparse.ArgumentParser(description="Convert from 1pux data format to csv") | |
parser.add_argument('input_file', type=str) | |
parser.add_argument('output_dir', nargs='?', default="", type=str) | |
args = parser.parse_args() | |
convert(args.input_file, args.output_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment