Last active
March 7, 2020 13:26
-
-
Save ryanpersaud/7900c35677b40aa06c8aa29388a7be3b to your computer and use it in GitHub Desktop.
Converts KeePass 1.x CSV to 1Password compatible CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from https://stackoverflow.com/questions/51397083/python-3-6-rename-column-header-using-dictwriter | |
import csv | |
order = ['Account', 'Web Site', 'Login Name', 'Password', 'Comments', 'Member Number', 'Recovery Codes'] | |
# define renamed columns via dictionary | |
renamer = {'Account': 'Title', 'Web Site' : 'Website', 'Login Name':'Username', 'Comments':'Notes'} | |
# define column names after renaming | |
new_cols = [renamer.get(x, x) for x in order] | |
# replace mystr as open(r'file.csv', 'r') | |
with open('password_keepass.csv', 'r') as fin, open('password_1password.csv', 'w', newline='') as fout: | |
# define reader / writer objects | |
reader = csv.DictReader(fin, delimiter=',') | |
writer = csv.writer(fout, delimiter=',', quoting=csv.QUOTE_ALL) | |
# write new header | |
writer.writerow(new_cols) | |
# iterate reader and write row | |
for item in reader: | |
writer.writerow([item.get(k, '') for k in order]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
quoting=csv.QUOTE_ALL may be unnecessary