comparison scripts/comment_parser.py @ 209:538322113524 Dev_main

Merge from the default branch
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Tue, 16 Jun 2015 14:14:08 +0100
parents 59eea6eed91b
children 625a0f709a55
comparison
equal deleted inserted replaced
204:d12dbbab3565 209:538322113524
9 root = tree.getroot() 9 root = tree.getroot()
10 10
11 # get list of all page names 11 # get list of all page names
12 for audioholder in root.findall("./audioholder"): # iterate over pages 12 for audioholder in root.findall("./audioholder"): # iterate over pages
13 page_name = audioholder.get('id') # get page name 13 page_name = audioholder.get('id') # get page name
14
15 if page_name is None: # ignore 'empty' audio_holders
16 break
14 17
15 # create folder [page_name] if not yet created 18 # create folder [page_name] if not yet created
16 if not os.path.exists(page_name): 19 if not os.path.exists(page_name):
17 os.makedirs(page_name) 20 os.makedirs(page_name)
18 21
19 # for page [page_name], print comments related to fragment [id] 22 # for page [page_name], print comments related to fragment [id]
20 for audioelement in root.findall("*/[@id='"+page_name+"']/audioelement"): 23 for audioelement in root.findall("*/[@id='"+page_name+"']/audioelement"):
21 audio_id = str(audioelement.get('id')) 24 if audioelement is not None: # Check it exists
22 # append to file [page_name]/[page_name]-comments-[id].csv 25 audio_id = str(audioelement.get('id'))
23 with open(page_name+'/'+page_name+'-comments-'+audio_id+'.csv', 'a') as csvfile:
24 commentstr = root.find("*/[@id='"
25 + page_name
26 + "']/audioelement/[@id='"
27 + audio_id
28 + "']/comment/response").text
29 writer = csv.writer(csvfile, delimiter=',')
30 writer.writerow([commentstr.encode("utf-8")])
31 #TODO Comma doesn't act as delimiter now!
32 # (when adding more than just a comment per line):
33 # writer.writerow([file + ',' + commentstr.encode("utf-8")])
34 26
35 #TODO Replace 'new line' with something else? 27 # append to file [page_name]/[page_name]-comments-[id].csv
28 with open(page_name+'/'+page_name+'-comments-'+audio_id+'.csv', 'a') as csvfile:
29 writer = csv.writer(csvfile, delimiter=',')
30 commentstr = root.find("*/[@id='"
31 + page_name
32 + "']/audioelement/[@id='"
33 + audio_id
34 + "']/comment/response").text
35 if commentstr is None:
36 writer.writerow([''])
37 else:
38 writer.writerow([commentstr.encode("utf-8")])
39 #TODO Comma doesn't act as delimiter now!
40 # (when adding more than just a comment per line):
41 # writer.writerow([file + ',' + commentstr.encode("utf-8")])
36 42
37 #TODO 'Append' means duplicate entries if run several times... 43 #TODO Replace 'new line' with something else?
38 44
45 #TODO 'Append' means duplicate entries if run several times...
46