This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protonpass_json_to_bitwarden_csv.py
79 lines (60 loc) · 2.52 KB
/
protonpass_json_to_bitwarden_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv
import json
from random import randint
with open('data.json', 'r') as f: # assume json is in the current directory
pws = json.load(f)
vaults = pws['vaults']
export = [] # blank list used later to store all the passwords getting exported
export_filename = f'export_{randint(0,10000)}.csv' # generate a random number for the output csv filename
print(export_filename)
for vault in vaults.keys():
print(vaults[vault]['name'], '\t', vault,)
for item in vaults[vault]['items']:
data = item['data']
content = data['content']
metadata = data['metadata']
# print(content)
# print(metadata)
pw = {}
if content == {}:
print(metadata['name'], 'HAS NO CONTENT')
continue
pw['name'] = metadata['name'] # Name
try:
pw['login_uri'] = content['urls'][0] # URL
except IndexError:
print(metadata['name'], 'HAS NO URLS')
pw['login_uri'] = ''
pw['login_username'] = content['username'] # Username
pw['login_password'] = content['password'] # Password
pw['folder'] = vaults[vault]['name'] # Folder (uses PP vault name)
pw['notes'] = metadata['note'] # Notes
# assume everything is a login - i only had logins.
pw['type'] = 'login'
pw['favorite'] = 0
pw['reprompt'] = 0
# stop extra fields exporting as '[]'
if data['extraFields']:
pw['fields'] = data['extraFields']
else:
pw['fields'] = ''
if content['totpUri']:
totp = content['totpUri'].split('?')[1].split('&')
# spliting on 0 leaves url and then the rest, split on & splits up the rest. then grab the one that has the secret
for item in totp:
if item[0:7] == 'secret=':
pw['login_totp'] = item[7:]
else:
pw['login_totp'] = ''
export.append(pw)
# Export to CSV
headers = ['name', 'login_uri', 'login_username', 'login_password', 'folder', 'notes', 'type', 'favorite', 'reprompt', 'fields', 'login_totp']
with open(export_filename, 'x', newline='') as expfile:
csvw = csv.writer(expfile)
csvw.writerow(headers)
for item in export:
x = []
for value in item.values():
x.append(value)
csvw.writerow(x)
input('\n\nprogram finished, file saved', export_filename)