number_of_unique_users.py 818 B

123456789101112131415161718192021222324252627282930
  1. '''
  2. This code is done as part of Udacity quizes throughout the course.
  3. I find out how many unique users
  4. have contributed to the map in this particular area!
  5. The function process_map returns a set of unique user IDs ("uid")
  6. '''
  7. # Initial imports
  8. import xml.etree.cElementTree as ET
  9. import pprint
  10. import re
  11. # Change this with the path of your OSM file
  12. OSMFILE = 'sample.osm'
  13. # Parsing the OSM and returning the 'uid' for node and way tags
  14. def process_map(filename):
  15. users = set()
  16. for _, element in ET.iterparse(filename):
  17. if element.tag == 'node' or element.tag == 'way' or element.tag == 'relation':
  18. userid = element.attrib['uid']
  19. users.add(userid)
  20. print(len(users))
  21. # Uncomment this section to see the output from calling the function
  22. # process_map(OSMFILE)