{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#users.py\n", "#Investigando usuários\n", "# https://classroom.udacity.com/nanodegrees/nd002/parts/0021345404/modules/316820862075462/lessons/768058569/concepts/8426285720923#\n", "#!/usr/bin/env python\n", "# -*- coding: utf-8 -*-\n", "import xml.etree.cElementTree as ET\n", "import pprint\n", "import re\n", "\"\"\"\n", "Your task is to explore the data a bit more.\n", "The first task is a fun one - find out how many unique users\n", "have contributed to the map in this particular area!\n", "\n", "The function process_map should return a set of unique user IDs (\"uid\")\n", "\"\"\"\n", "\n", "osm_file = open(\"/media/vagner/Seagate Expansion Drive/500Gb/\"+\n", " \"DiskExternoVagner/Cursos/CientistaDados/\"+\n", " \"Modulo_4/DW-OSM-RMSP/sample.osm\", \"r\")\n", "\n", "\n", "def get_user(element):\n", " # see if the key exists:\n", " if element.get('uid'):\n", " uid = element.attrib[\"uid\"]\n", " return uid\n", " else:\n", " # you want this function to return None if the key doesn't exist\n", " return None\n", "\n", "\n", "def process_map():\n", " users = set()\n", " for _, element in ET.iterparse(osm_file):\n", " if get_user(element):\n", " users.add(element.attrib[\"uid\"])\n", " return users\n", "\n", "def test():\n", "\n", " users = process_map()\n", " print len(users)\n", " print(users)\n", " \n", "if __name__ == \"__main__\":\n", " test()\n", " osm_file.close()" ] } ], "metadata": { "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 1 }