Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xml.etree.cElementTree as ET
- #from collections import defaultdict
- import re
- #import pprint
- OSMFILE = "sample.osm"
- def update_phones(phone):
- #remove all non character digit
- n=''.join(ele for ele in phone if ele.isdigit())
- # if phone has 1 in front, drop 1 (no area code begins with 1) and update it.
- if n[0] == 1:
- update_numbers = format(int(n[1:-1]), ",").replace(",", "-") + n[-1]
- #store phone # with missing area codes in "Miss_area_code" list
- Miss_area_code = []
- if len(n)< 10:
- Miss_area_code.append(phone)
- print Miss_area_code
- if len(n) == 10:
- # then separate the thousand by "," and then replace "," with "-", and add the last digit.
- update_numbers = format(int(n[:-1]), ",").replace(",", "-") + n[-1]
- update_numbers.append(phone)
- return update_numbers
- print update_numbers
- def is_phone(elem):
- return (elem.attrib['k'] == "phone") # look for attrib 'k' with value 'phone'
- def audit(osmfile):
- osm_file = open(osmfile, "r")
- for event, elem in ET.iterparse(osm_file, events=("start",)):
- if elem.tag == "node" or elem.tag == "way":
- for tag in elem.iter("tag"):
- if is_phone(tag): # from the def above, with "k"= "phone"
- update_numbers(update_phones(tag.attrib['v'])) # go through the def above with attrib "v"
- osm_file.close()
- #print (street_types)
- return update_numbers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement