#lastpass and keepass use different formated csv files
#this will transform a lastpass csv file to a keepass csv file
#quick and dirty only for my personal use
#may contain problems if lsatpass does not use utf-8
import csv
import re
csv.register_dialect('lastpass', delimiter=',', quoting=csv.QUOTE_MINIMAL, \
doublequote=True, quotechar='"')
csv.register_dialect('keepass', delimiter=',', quoting=csv.QUOTE_ALL, \
doublequote=False, quotechar='"', escapechar = "\\")
inputfile = "in.csv"
outputfile = "out.csv"
incsv = csv.reader(open(inputfile, 'rb'), "lastpass")
outcsv = csv.writer(open(outputfile, 'wb'), "keepass")
header = incsv.next()
if not header == ["url", "username", "password", "extra", "name", "grouping", "fav"]:
print "Something is wrong!!!"
for row in incsv:
[url, username, password, extra, name, grouping, fav] = row
if password == "":
print row
outcsv.writerow([name, username, password, url, extra])