-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.py
70 lines (62 loc) · 2.3 KB
/
converter.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
import csv
import sys
csvFile = open('export.csv', 'w')
csvWriter = csv.writer(csvFile, quoting=csv.QUOTE_MINIMAL)
csvWriter.writerow(['title', 'username', 'password', 'notes'])
importSocket = open(sys.argv[1], 'r')
importFile = importSocket.readlines()
importSocket.close()
# Concatenate strings
myList = []
temp = ''
for line in importFile:
if line != '\n':
temp = temp + line
elif temp != '':
myList.append(temp)
temp = ''
if temp != '':
myList.append(temp)
# Create entry
def constructLine(splittedItem):
entry = []
notes = ''
withoutUsername = True
withoutPassword = True
usernameAsEmail = False
# Try to find `Username`
for line in splittedItem:
if line.startswith('Username'):
withoutUsername = False
entry.append(line.replace('Username ', ''))
# If there is no `Username` field — try to find `E-Mail` and use it as `Username`
if withoutUsername:
for line in splittedItem:
if (line.startswith('E-Mail') or line.startswith('Email') or line.startswith('E-mail')):
withoutUsername = False
usernameAsEmail = True
entry.append(line.replace('E-Mail ', '').replace('Email ', '').replace('E-mail', ''))
# If there is no `E-Mail` — field is filled with `none`
if withoutUsername:
entry.append('none')
# Try to find `Password`
for line in splittedItem:
if line.startswith('Password'):
withoutPassword = False
entry.append(line.replace('Password ', ''))
# If there is no `Password` — field is filled with `none`
if withoutPassword:
entry.append('none')
# Everything else goes to `notes` section
for line in splittedItem:
if (not line.startswith('Password') and not line.startswith('Username')) and not ((line.startswith('E-Mail') or line.startswith('Email') or line.startswith('E-mail')) and usernameAsEmail):
notes += line.replace('Url ', '').replace('E-Mail ', '').replace('Email ', '').replace('E-mail', '')
entry.append(notes)
return entry
# Iterate array, close file
for item in myList:
splittedItem = item.split('\n')
# First entry always a name
name = splittedItem.pop(0)
csvWriter.writerow([name] + constructLine(splittedItem))
csvFile.close()