Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1.  
  2. import xml.etree.cElementTree as ET
  3. #from collections import defaultdict
  4. import re
  5. #import pprint
  6.  
  7. OSMFILE = "sample.osm"
  8.  
  9. def update_phones(phone):
  10. #remove all non character digit
  11. n=''.join(ele for ele in phone if ele.isdigit())
  12. # if phone has 1 in front, drop 1 (no area code begins with 1) and update it.
  13. if n[0] == 1:
  14. update_numbers = format(int(n[1:-1]), ",").replace(",", "-") + n[-1]
  15.  
  16. #store phone # with missing area codes in "Miss_area_code" list
  17. Miss_area_code = []
  18.  
  19. if len(n)< 10:
  20. Miss_area_code.append(phone)
  21. print Miss_area_code
  22.  
  23. if len(n) == 10:
  24.  
  25. # then separate the thousand by "," and then replace "," with "-", and add the last digit.
  26. update_numbers = format(int(n[:-1]), ",").replace(",", "-") + n[-1]
  27. update_numbers.append(phone)
  28. return update_numbers
  29. print update_numbers
  30.  
  31.  
  32.  
  33. def is_phone(elem):
  34. return (elem.attrib['k'] == "phone") # look for attrib 'k' with value 'phone'
  35.  
  36.  
  37. def audit(osmfile):
  38. osm_file = open(osmfile, "r")
  39.  
  40. for event, elem in ET.iterparse(osm_file, events=("start",)):
  41.  
  42. if elem.tag == "node" or elem.tag == "way":
  43. for tag in elem.iter("tag"):
  44. if is_phone(tag): # from the def above, with "k"= "phone"
  45. update_numbers(update_phones(tag.attrib['v'])) # go through the def above with attrib "v"
  46.  
  47. osm_file.close()
  48. #print (street_types)
  49. return update_numbers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement