Skip to content

Instantly share code, notes, and snippets.

@joswr1ght
Created June 14, 2019 19:09
Show Gist options
  • Save joswr1ght/cbb1e07564de94729c0e375b38815b6c to your computer and use it in GitHub Desktop.
Save joswr1ght/cbb1e07564de94729c0e375b38815b6c to your computer and use it in GitHub Desktop.
OneSafe to 1Password Conversion
#!/usr/bin/env python3
# 2019-06-14 Joshua Wright, [email protected]
import csv
import sys
OV = '\x1b[0;33m' # verbose
OR = '\x1b[0;36m' # routine
OE = '\x1b[1;31m' # error
OM = '\x1b[0m' # mischief managed
LOGINFILE="1password-login.csv"
CCFILE="1password-cc.csv"
NOTESFILE="1password-notes.csv"
if len(sys.argv) != 2:
sys.stdout.write(f"Usage: {sys.argv[0]} <onesafeexport.csv>\n")
sys.stdout.write(f"\nWill create three output files in the current directory: {LOGINFILE}, {CCFILE}, " \
f"and {NOTESFILE}.\n")
sys.exit(1)
with open(sys.argv[1]) as csv_file:
try:
csv_reader = csv.reader(csv_file, delimiter=';')
except Exception as ex:
sys.stdout.write(f'{OE}Exception parsing CSV file {LOGINFILE} (invalid OneSafe export?): {OR}{ex}{OM}')
sys.exit(-1)
## Open the output files
try:
output_file_login = open(LOGINFILE, "w")
except Exception as ex:
sys.stdout.write(f'{OE}Exception occurred opening {LOGINFILE}: {OR}{ex}{OM}')
sys.exit(-1)
try:
output_file_cc = open(CCFILE, "w")
except Exception as ex:
sys.stdout.write(f'{OE}Exception occurred opening {CCFILE}: {OR}{ex}{OM}')
sys.exit(-1)
try:
output_file_notes = open(NOTESFILE, "w")
except Exception as ex:
sys.stdout.write(f'{OE}Exception occurred opening {NOTESFILE}: {OR}{ex}{OM}')
sys.exit(-1)
# Header records are not required for 1Password import; left here for documentation
#output_file_login.write("title,website,username,password,notes\n")
#output_file_cc.write("title,card number,expiry date (MM/YYYY),cardholder name,PIN,bank name,CVV,notes\n")
#output_file_notes.write("title,text of note\n")
line_count = 0
for row in csv_reader:
if line_count == 0:
# Skip the OneSafe header record
line_count += 1
else:
# Login Records
# OneSafe: Title;Template;URL;App Name;User Name;Password;Note
if (row[1] == "Regular Web Account" or row[1] == "Google ID" or row[1] == "Gmail" \
or ".com" in row[2]):
output_file_login.write(f'"{row[0]}","{row[2]}","{row[4]}","{row[5]}","{row[6]}"\n')
elif (row[1] == "Linux"):
output_file_login.write(f'"{row[1]} - {row[0]}",,"{row[4]}","{row[5]}","{row[33]}"\n')
elif (row[1] == "SSH Account"):
output_file_login.write(f'"{row[1]} - {row[0]}",,"{row[4]}","{row[5]}","SSH Server: {row[2]}"\n')
elif ("Mac OS" in row[1]):
output_file_login.write(f'"UNIX - {row[0]}",,"{row[4]}","{row[5]}","SSH Server: {row[0]}"\n')
elif (row[1] == "Database"):
output_file_login.write(f'"{row[1]} - {row[0]}",,"{row[4]}","{row[5]}","Database Server: {row[22]}" | ' \
f'Port: "{row[23]}" | Database Name: "{row[24]}"\n')
elif (row[1] == "Skype"):
output_file_login.write(f'"{row[0]}",www.skype.com,"{row[4]}","{row[5]}",""\n')
elif (row[1] == "Apple ID"):
output_file_login.write(f'"{row[0]}",www.apple.com,"{row[15]}","{row[5]}",""\n')
elif (row[1] == "Instant Messenger"):
output_file_login.write(f'"{row[1]} - {row[0]}",,"{row[4]}","{row[5]}",""\n')
elif (row[1] == "Locker Combination"):
output_file_login.write(f'"{row[1]} - {row[0]}",,"{row[34]}","{row[35]}",""\n')
elif (row[1] == "Wordpress Blog"):
output_file_login.write(f'"{row[1]} - {row[0]}","{row[2]}","{row[4]}","{row[5]}",""\n')
elif (row[1] == "Network Connection"):
output_file_login.write(f'"{row[1]} - {row[0]}","{row[36]}",,"{row[14]}",""\n')
# Credit Card
# 1Password Format: title,card number,expiry date (MM/YYYY),cardholder name,PIN,bank name,CVV,notes
elif (row[18] != ""): # Credit Card Number
output_file_cc.write(f'{row[0]} - {row[1]},{row[19].replace(" ","")},{row[21]},{row[20]},,,{row[18]},\n')
# Secure Notes
# 1Password Format: title,text of note
elif (row[1] == "ID Card"):
output_file_notes.write(f'{row[1]} - {row[0]},{row[14]}\n')
else:
print(f'{", ".join(row)}')
line_count += 1
# Close output files
output_file_login.close()
output_file_notes.close()
output_file_cc.close()
print(f'Processed {line_count} records.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment