Mercurial > hg > webaudioevaluationtool
comparison scripts/comment_parser.py @ 921:533d51508e93
Stash for project creator
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Mon, 01 Jun 2015 12:55:21 +0100 |
parents | |
children | 070a90d1117c 4a0bfa7bef24 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 921:533d51508e93 |
---|---|
1 import xml.etree.ElementTree as ET | |
2 import os | |
3 import csv | |
4 | |
5 # get every XML file in folder | |
6 for file in os.listdir("."): # You have to put this script in folder where output XML files are. | |
7 if file.endswith(".xml"): | |
8 tree = ET.parse(file) | |
9 root = tree.getroot() | |
10 | |
11 # get list of all page names | |
12 for audioholder in root.findall("./audioholder"): # iterate over pages | |
13 page_name = audioholder.get('id') # get page name | |
14 | |
15 # create folder [page_name] if not yet created | |
16 if not os.path.exists(page_name): | |
17 os.makedirs(page_name) | |
18 | |
19 # for page [page_name], print comments related to fragment [id] | |
20 for audioelement in root.findall("*/[@id='"+page_name+"']/audioelement"): | |
21 audio_id = str(audioelement.get('id')) | |
22 # append to file [page_name]/[page_name]-comments-[id].csv | |
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 | |
35 #TODO Replace 'new line' with something else? | |
36 | |
37 #TODO 'Append' means duplicate entries if run several times... | |
38 |