Skip to content

Instantly share code, notes, and snippets.

@6d61726b760a
Last active June 11, 2020 03:44
Show Gist options
  • Save 6d61726b760a/6a3bc08aade470ae4e4cb747d5588ccc to your computer and use it in GitHub Desktop.
Save 6d61726b760a/6a3bc08aade470ae4e4cb747d5588ccc to your computer and use it in GitHub Desktop.
import csv
'''
export a 1password csv formatted file to lastpass csv formatted file
this is really only suitable for logins only
essentially we are just renaming the following fields
title > name
username > username
password > password
url > url
anything that is not one of these fields gets appended to the "extra"
field, which appears in lastpass as notes
'''
with open('1password_logins.csv', mode='r') as csv_infile:
csv_reader = csv.DictReader(csv_infile)
line_count = 0
columns = []
for row in csv_reader:
with open('lastpass_logins.csv', 'a+', newline='') as csv_outfile:
columns = [ 'name', 'url','username','password','extra' ]
writer = csv.DictWriter(csv_outfile, fieldnames=columns)
if line_count == 0:
writer.writeheader()
line_count += 1
newrow = {}
newrow['extra'] = None
for column in row:
value = ""
if column == 'TITLE':
newrow['name'] = row[column]
elif column == 'URL':
newrow['url'] = row[column]
elif column == 'USERNAME':
newrow['username'] = row[column]
elif column == 'PASSWORD':
newrow['password'] = row[column]
else:
if row[column] != "":
if newrow['extra'] == None:
newrow['extra'] = f"{column}: {row[column]}"
else:
newrow['extra'] = f"{newrow['extra']} \t {column}: {row[column]}"
writer.writerow(newrow)
line_count += 1
print(f'Processed {line_count} lines.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment