Skip to content

Instantly share code, notes, and snippets.

@nico-zck
Created February 2, 2021 06:14
Show Gist options
  • Save nico-zck/2ad8a0952ee6013e760f92fb8f4d7f08 to your computer and use it in GitHub Desktop.
Save nico-zck/2ad8a0952ee6013e760f92fb8f4d7f08 to your computer and use it in GitHub Desktop.
Convert 1pass exported file to Bitwarden supported csv file.
import json
import pandas as pd
try:
with open("data.1pif", "r") as f:
lines = f.readlines()
lines = [l for l in lines if not l.startswith("***")]
data = json.loads("[" + ",".join(lines) + "]")
except:
print("data.1pif is not properly prepared.")
data_converted = []
for i, sample in enumerate(data):
try:
if sample["typeName"] == "wallet.financial.CreditCard":
continue
name = sample["title"]
username = password = ""
for sc in sample["secureContents"]["fields"]:
if "designation" not in sc:
continue
if sc["designation"] == "username":
username = sc["value"]
if sc["designation"] == "password":
password = sc["value"]
if "URLs" in sample["secureContents"]:
url = ",".join([_["url"] for _ in sample["secureContents"]["URLs"]])
else:
url = ""
if "openContents" in sample:
grouping = sample["openContents"]["tags"][0]
else:
grouping = ""
data_converted.append(
dict(
name=name,
login_username=username,
login_password=password,
login_uri=url,
folder=grouping,
)
)
except:
print(i, " ", end="")
print(sample)
exit()
df = pd.DataFrame(data_converted)
df.to_csv("data_bitwarden.csv", index=False)
print()
print("there are %d login items" % len(df))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment