Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Please help with integrating the ```update_name``` and ```update_number``` into the ```shape_element``` function.
- Note: all of these functions work fine independently
- '''
- def phone(osm_file):
- '''
- Gets phone numbers from the XML file
- '''
- # open file
- osm_file = open(file_path, "r")
- num = []
- # reach phone num
- for event, elem in ET.iterparse(osm_file, events=("start",)):
- if elem.tag == "node":
- for tag in elem.iter("tag"):
- if tag.attrib['k'] == 'phone':
- num.append(tag.attrib['v'])
- return num
- phone(osm_file)
- def std_phone(num):
- '''
- Standardizes phone number
- '''
- fixed_num = []
- for i in num:
- num = i
- # Remove anything that is not a number
- num = re.sub('[^0-9]+', '', num)
- # add dashes to 10 digit nums
- if re.match(r'^\d{10}$', num) is not None:
- num = num[:3] + '-' + num[3:6]+ '-' + num[6:]
- fixed_num.append(num)
- # add dashes to 11 digit nums
- elif re.match(r'^\d{11}$', num) is not None:
- num = num[0] + '-' + num[1:4] + '-' + num[4:7] + '-' +num[7:]
- fixed_num.append(num)
- def update_name(name, mapping):
- '''
- 1.Removes APT and house numbers from the street address
- 2.Using a regex function to search for problematic names,
- then modifies it according to the given mapping.
- Args:
- name(string): potential problematic street name
- mapping(dict): the desired outcome of street suffixes
- Returns:
- name(string): All street names (fixed and non-fixed)
- '''
- if '#' in name:
- name = name.split('#',-1)[0].strip()
- if ',' in name:
- name = name.split(',', 1)[0].strip()
- m = street_type_re.search(name)
- if m:
- street_type = m.group()
- if street_type not in expected: # This is somewhat redundant, but it acts as a fail-safe
- if street_type in mapping:
- name= re.sub(street_type_re, mapping[street_type] , name)
- return name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement