Rub21
3/11/2014 - 6:47 PM

school_fixed.py

from sys import argv, exit
import xml.parsers.expat

theglobal = {}
thetag_amenity={}
thetag_building={}
out = '<osmChange version="0.6" generator="schools_fixes.py"><modify>'
count = 0
file_count = 0

ban_theglobal = False
ban_thetag_amenity=False
ban_thetag_building=False



def start_element(name, attrs):
    accepted = ['node', 'way', 'relation']
    #print accepted
    #print name
    if name in accepted:
        global theglobal
        print name
        theglobal['name'] = name
        theglobal['attrs'] = attrs
        ban_theglobal=True
        #print attrs


    #<tag k='amenity' v='school' />
    #<tag k='building' v='yes' />

    if (name == 'tag' and 'k' in attrs and  attrs['k'] == 'amenity' and 'v' in attrs and  attrs['v'] == 'school'):
        global thetag_amenity  
        thetag_amenity['name'] = name
        thetag_amenity['attrs'] = attrs
        print thetag_amenity
        ban_thetag_amenity=True

    if (name == 'tag' and 'k' in attrs and  attrs['k'] == 'building' and 'v' in attrs and  attrs['v'] == 'yes' and ban_thetag_amenity):
        global thetag_building  
        thetag_building['name'] = name
        thetag_building['attrs'] = attrs
        print thetag_building
        ban_thetag_building=True



def end_element(name):
    a=name
        #print out



p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = start_element
p.EndElementHandler = end_element

p.ParseFile(open('nycs.osm', 'r'))