import xml.etree.cElementTree as ET
import Queue
import pprint
def count_tags(filename):
nodes = {'bounds': 0,
'member': 0,
'nd': 0,
'node': 0,
'osm': 0,
'relation': 0,
'tag': 0,
'way': 0}
myqueue = Queue.Queue()
tree = ET.parse(filename)
root = tree.getroot()
myqueue.put(root)
nodes["osm"] += 1
tag = root.tag
while myqueue.empty() == False:
node = myqueue.get()
for i in node:
myqueue.put(i)
print(i.tag)
if i.tag == "node":
nodes["node"] += 1
elif i.tag == "nd":
nodes["nd"] += 1
elif i.tag == "member":
nodes["member"] += 1
elif i.tag == "bounds":
nodes["bounds"] += 1
elif i.tag == "relation":
nodes["relation"] += 1
elif i.tag == "tag":
nodes["tag"] += 1
elif i.tag == "way":
nodes["way"] += 1
else:
continue
print(myqueue.qsize())
return nodes
# YOUR CODE HERE
def test():
tags = count_tags('example.osm')
pprint.pprint(tags)
assert tags == {'bounds': 1,
'member': 3,
'nd': 4,
'node': 20,
'osm': 1,
'relation': 1,
'tag': 7,
'way': 1}