-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
52 lines (44 loc) · 1.21 KB
/
parser.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
#!/usr/bin/env python3
from xml.dom.minidom import parse
# encountered a ReadingList text node?
reading_list = False
# encountered a URLString text node?
url_string = False
# encountered a title text node?
title = False
title_s = ''
urls = []
def goParse(node):
global reading_list
global urls
global url_string
global title
global title_s
if node is None:
return
if node.nodeValue == "ReadingList":
reading_list = True
elif reading_list is True and node.nodeValue == "title":
title = True
elif title is True and node.nodeType == node.ELEMENT_NODE:
if node.firstChild is not None:
title_s = ''.join(node.firstChild.nodeValue)
title = False
elif reading_list is True and node.nodeValue == "URLString":
url_string = True
elif url_string is True and node.nodeType == node.ELEMENT_NODE:
# well this is fun
urls.append((title_s, ''.join(node.firstChild.nodeValue)))
reading_list = False
url_string = False
title = False
for child in node.childNodes:
goParse(child)
document = parse("Bookmarks.plist.xml")
goParse(document)
with open('ReadingList.md', 'w') as f:
for u in urls:
f.write(u[0])
f.write('\n\n')
f.write(u[1])
f.write('\n\n')