Skip to content

Instantly share code, notes, and snippets.

@andsens
Created March 3, 2015 22:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andsens/085de9978260d4159a67 to your computer and use it in GitHub Desktop.
Save andsens/085de9978260d4159a67 to your computer and use it in GitHub Desktop.
Converts a passpack csv export to a lastpass csv export
#!/usr/bin/env python
from collections import Counter
import csv
all_tags = []
lines = []
with open('passpack.csv') as passwords_handle:
passwords = csv.reader(passwords_handle, delimiter=',',
quotechar='"', quoting=csv.QUOTE_MINIMAL)
passwords.next()
for line in passwords:
[name, username, password, url, tags, notes, email] = line
lines.append(line)
all_tags.extend(filter(lambda tag: tag != '', tags.split(' ')))
tag_priority = [tag for (tag, count) in sorted(Counter(all_tags).items(), key=lambda x: x[1])]
def group(keys):
winner = None
winner_score = 0
for key in keys:
score = tag_priority.index(key)
if score > winner_score:
winner = key
winner_score = score
return winner
names = set()
urls = set()
with open('passwords.out.csv', 'wb') as out_handle:
passwords_out = csv.writer(out_handle, delimiter=',',
quotechar='"', quoting=csv.QUOTE_ALL)
passwords_out.writerow(['url', 'username', 'password', 'extra', 'name', 'grouping', 'fav'])
for line in lines:
[name, username, password, url, tags, notes, email] = line
grouping = group(filter(lambda tag: tag != '', tags.split(' ')))
if url == '':
print('Warning: {name} does not have a URL'.format(name=name))
url = name
passwords_out.writerow([url, username, password, notes, name, grouping, 0])
if name in names:
print('Warning: {name} occurs more than once'.format(name=name))
else:
names.add(name)
print('Converted {count} passwords'.format(count=len(lines)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment