-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
67 lines (55 loc) · 1.93 KB
/
parser.py
File metadata and controls
67 lines (55 loc) · 1.93 KB
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
from xml.dom.minidom import parse
import sys
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
globalid = 1
def genId():
global globalid
ret = globalid
globalid += 1
return ret
def getText(nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
def handleSheet(node):
if node.firstChild.nodeName == 'topic':
handleTopic(node.firstChild, 0)
def handleTopic(topic, parentId):
nodeid = genId()
nodetype = 0
nodelabel = ''
nodetitle = ''
nodenote = ''
nodetext = ''
children = topic.childNodes
for node in children:
if node.nodeName == 'marker-refs':
marker = node.firstChild.attributes['marker-id'].value
if marker == 'priority-1':
nodetype = 1
elif marker == 'priority-2':
nodetype = 2
elif marker == 'priority-3':
nodetype = 3
elif node.nodeName == 'labels':
nodelabel = node.firstChild.firstChild.data
elif node.nodeName == 'children':
for child in node.childNodes:
if child.nodeName == 'topics':
for childtopic in child.childNodes:
handleTopic(childtopic, nodeid)
elif node.nodeName == 'title':
nodetitle = getText(node.childNodes)
elif node.nodeName == 'notes':
nodenote = node.getElementsByTagName('plain')[0].firstChild.data
nodetext = nodetitle + "\n" + nodenote
#nodetext = nodetext.replace("\n", "\\n")
output = """insert into nodes (nodeindex, nodetype, parentindex, label, message) values(%d,%d,%d,'%s','%s');""" % (nodeid, nodetype, parentId, nodelabel, nodetext)
output.encode('UTF-8')
sys.stdout.write(output)
sys.stdout.write(u"\r\n")
dom = parse('content.xml')
handleSheet(dom.getElementsByTagName('sheet')[0])