Skip to content

Instantly share code, notes, and snippets.

@bkbilly
Last active June 14, 2023 20:40
Show Gist options
  • Save bkbilly/7be39e0d65b0226ae6bf741dc3c814d4 to your computer and use it in GitHub Desktop.
Save bkbilly/7be39e0d65b0226ae6bf741dc3c814d4 to your computer and use it in GitHub Desktop.
Converts the XML files exported by Sticky Password to CSV format for import to Chrome or Firefox.
import xmltodict
import pprint
import csv
# Make sure you convert the xml file to UTF-8
in_xml = "stickypassword.xml"
out_csv = "pass.csv"
pp = pprint.PrettyPrinter(depth=2)
with open(in_xml) as fd:
mfile = fd.read()
doc = xmltodict.parse(mfile)
# pp.pprint(doc['root']['Database'])
logins = {}
for login in doc['root']['Database']['Logins']['Login']:
logins[login["@ID"]] = {
"name": login["@Name"],
"username": login.get("@RealLogin", login["@Name"]),
"password": login["@Password"],
}
# pp.pprint(logins)
accounts = [['name', 'url', 'username', 'password', 'note']]
for account in doc['root']['Database']['Accounts']['Account']:
url = account['@Link']
print(url)
loginlinks = account['LoginLinks']['Login']
if isinstance(loginlinks, dict):
loginlinks = [loginlinks]
for loginlink in loginlinks:
loginf = logins[loginlink['@SourceLoginID']]
print(f" {loginf}")
accounts.append([loginf['name'], url, loginf['username'], loginf['password'], ''])
with open(out_csv, 'w') as f:
write = csv.writer(f)
write.writerows(accounts)
print(f"XML passwords converted to csv: {out_csv}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment