#users.py
#Investigando usuários
# https://classroom.udacity.com/nanodegrees/nd002/parts/0021345404/modules/316820862075462/lessons/768058569/concepts/8426285720923#
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.cElementTree as ET
import pprint
import re
"""
Your task is to explore the data a bit more.
The first task is a fun one - find out how many unique users
have contributed to the map in this particular area!
The function process_map should return a set of unique user IDs ("uid")
"""
osm_file = open("/media/vagner/Seagate Expansion Drive/500Gb/"+
"DiskExternoVagner/Cursos/CientistaDados/"+
"Modulo_4/DW-OSM-RMSP/sample.osm", "r")
def get_user(element):
# see if the key exists:
if element.get('uid'):
uid = element.attrib["uid"]
return uid
else:
# you want this function to return None if the key doesn't exist
return None
def process_map():
users = set()
for _, element in ET.iterparse(osm_file):
if get_user(element):
users.add(element.attrib["uid"])
return users
def test():
users = process_map()
print len(users)
print(users)
if __name__ == "__main__":
test()
osm_file.close()