-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPS6_users.py
41 lines (29 loc) · 863 Bytes
/
PS6_users.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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")
"""
def get_user(element):
if element.tag in ["node", "way", "relation"]:
return element.attrib["uid"]
else:
return None
def process_map(filename):
users = set()
for _, element in ET.iterparse(filename):
uid = get_user(element)
if uid: # if get_user returns None, we ignore it
users.add(uid)
return users
def test():
users = process_map('example.osm')
pprint.pprint(users)
assert len(users) == 6
if __name__ == "__main__":
test()