Skip to content

Instantly share code, notes, and snippets.

@egorsmkv
Created May 10, 2016 10:13
Show Gist options
  • Save egorsmkv/be75c1784e29e1d2eafc83fb26ed47a8 to your computer and use it in GitHub Desktop.
Save egorsmkv/be75c1784e29e1d2eafc83fb26ed47a8 to your computer and use it in GitHub Desktop.
Import LastPass to KeePassX
"""
Script for import your LastPass passwords to KeePassX.
"""
from lastpass import Vault
from kppy.database import KPDBv1
from urllib.parse import urlparse
LASTPASS_USERNAME = '***@gmail.com'
LASTPASS_PASSWORD = '***'
KEEPASSX_PASSWORD = '***'
KEEPASSX_KDB = '/home/***/Secret Data/passwords.kdb'
KEEPASSX_KEY = '/home/***/Secret Data/password.key'
def main():
db = KPDBv1(KEEPASSX_KDB, KEEPASSX_PASSWORD, KEEPASSX_KEY)
db.load()
groups = dict()
for group in db.groups:
name = group.title
if name not in groups:
groups[name] = group
def decode(value):
return value.decode('utf-8')
vault = Vault.open_remote(LASTPASS_USERNAME, LASTPASS_PASSWORD)
for entry in vault.accounts:
group_title = decode(entry.group)
if not len(group_title):
group_title = 'No category'
if group_title not in groups:
db.create_group(group_title)
db.save()
groups[group_title] = db.groups[-1]
url = urlparse(decode(entry.url))
url = '{}://{}'.format(url.scheme, url.netloc)
username, password = decode(entry.username), decode(entry.password)
db.create_entry(group=groups[group_title], title=decode(entry.name),
url=url, username=username, password=password)
db.save()
db.close()
print('Done.')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment