-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_csv_xml.py
46 lines (41 loc) · 1.19 KB
/
convert_csv_xml.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
#!/usr/bin/env python
import datetime
import fileinput
import string
import uuid
def repl_chars(s):
s = s.replace("&","&")
s = s.replace("<","<")
s = s.replace(">",">")
s = s.replace("\"",""")
s = s.replace("\'","'")
return s
print("<!DOCTYPE KEEPASSX_DATABASE>")
print("<database>")
print("<group>")
print("<title>Internet</title>")
print("<icon>1</icon>")
d = datetime.datetime.now()
d = d.replace(microsecond=0)
ds = d.isoformat()
first_line = True
# Iterate through the file a line at a time
for line in fileinput.input():
if not first_line:
print("<entry>")
entries = [ e.strip('"') for e in line.split(',') ]
print("\t<title>%s</title>" % entries[0])
print("\t<username>%s</username>" % entries[1])
print("\t<password>%s</password>" % repl_chars(entries[2]))
print("\t<url></url>")
print("\t<comment></comment>")
print("\t<icon>1</icon>")
print("\t<creation>%s</creation>" % ds)
print("\t<lastaccess>%s</lastaccess>" % ds)
print("\t<lastmod>%s</lastmod>" % ds)
print("\t<expire>Never</expire>")
print("</entry>")
else:
first_line = False
print("</group>")
print("</database>")