Add argparse for parameters. Also make pycodestyle (mostly) happy.
This commit is contained in:
parent
067efa5948
commit
8a2ee2c4d6
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,5 +2,5 @@
|
|||||||
/.venv/
|
/.venv/
|
||||||
/env
|
/env
|
||||||
*.1pif
|
*.1pif
|
||||||
out.kdbx
|
*.kdbx
|
||||||
*.xml
|
*.xml
|
||||||
|
28
convert.py
28
convert.py
@ -1,14 +1,29 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import shutil
|
|
||||||
import json
|
import json
|
||||||
|
import pathlib
|
||||||
|
|
||||||
from pykeepass import PyKeePass, create_database
|
from os.path import splitext
|
||||||
|
from pykeepass import create_database
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
kp = create_database("out.kdbx", password="test")
|
parser = argparse.ArgumentParser(description="Convert 1Password 1PIF exports into a KeePass KDBX file.")
|
||||||
|
parser.add_argument("inpath", metavar="input.1pif", help="1Password export file/folder")
|
||||||
|
parser.add_argument("outfile", metavar="output.kdbx", nargs="?", help="Desired filename for KeePass file. If omitted, defaults to <input>.kdbx. Existing files WILL BE OVERWRITTEN!")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if not args.outfile:
|
||||||
|
fileparts = splitext(args.inpath)
|
||||||
|
args.outfile = "{}.kdbx".format(fileparts[0])
|
||||||
|
|
||||||
|
outparts = splitext(args.outfile)
|
||||||
|
if not outparts[1] == "kdbx":
|
||||||
|
args.outfile += ".kdbx"
|
||||||
|
|
||||||
|
kp = create_database(args.outfile, password="test")
|
||||||
|
|
||||||
groupLabels = {
|
groupLabels = {
|
||||||
"passwords.Password": "Passwords",
|
"passwords.Password": "Passwords",
|
||||||
@ -24,6 +39,7 @@ groupLabels = {
|
|||||||
}
|
}
|
||||||
groups = {}
|
groups = {}
|
||||||
|
|
||||||
|
|
||||||
def getGroup(item):
|
def getGroup(item):
|
||||||
group = groups.get(item["typeName"])
|
group = groups.get(item["typeName"])
|
||||||
if group:
|
if group:
|
||||||
@ -37,6 +53,7 @@ def getGroup(item):
|
|||||||
groups[item["typeName"]] = group
|
groups[item["typeName"]] = group
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
|
||||||
def getField(item, designation):
|
def getField(item, designation):
|
||||||
secure = item["secureContents"]
|
secure = item["secureContents"]
|
||||||
if "fields" in secure:
|
if "fields" in secure:
|
||||||
@ -48,7 +65,7 @@ def getField(item, designation):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
with open("in.1pif/data.1pif", "r") as fp:
|
with open("{}/data.1pif".format(args.inpath), "r") as fp:
|
||||||
data = fp.read().strip().split("***5642bee8-a5ff-11dc-8314-0800200c9a66***")
|
data = fp.read().strip().split("***5642bee8-a5ff-11dc-8314-0800200c9a66***")
|
||||||
|
|
||||||
for line in data:
|
for line in data:
|
||||||
@ -173,7 +190,6 @@ for line in data:
|
|||||||
settings["Allow"] = list(set(settings["Allow"]))
|
settings["Allow"] = list(set(settings["Allow"]))
|
||||||
entry.set_custom_property("KeePassHttp Settings", json.dumps(settings))
|
entry.set_custom_property("KeePassHttp Settings", json.dumps(settings))
|
||||||
|
|
||||||
|
|
||||||
# Dates
|
# Dates
|
||||||
entry.ctime = datetime.datetime.fromtimestamp(item["createdAt"])
|
entry.ctime = datetime.datetime.fromtimestamp(item["createdAt"])
|
||||||
entry.mtime = datetime.datetime.fromtimestamp(item["updatedAt"])
|
entry.mtime = datetime.datetime.fromtimestamp(item["updatedAt"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user