def zipcodes_list(st_items): # If st_items is a single zipcode string. if isinstance(st_items, str): zc_objects = zipcode.islike(st_items) output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects] # If st_items is a list of zipcode strings. elif isinstance(st_items, list): zc_objects = [n for i in st_items for n in zipcode.islike(str(i))] output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects] else: raise ValueError("arg 'st_items' must be of type str or list") return (output)
def find_all_zipcode(zip_items): if type(zip_items) == str: zipcode_obj = zipcode.islike(zip_items) output = re.findall('\d+', str(zipcode_obj)) elif type(zip_items) == list: output = [ n for each in zip_items for n in re.findall('\d+', str(zipcode.islike(each))) ] else: raise ValueError("input 'zip_items' must be of type str or list") return output
def zipcodes_list(st_items): # If st_items is a single zipcode string. if type(st_items) == str: zcObjects = zipcode.islike(st_items) output = [str(i).split(" ", 1)[1].split(">")[0] for i in zcObjects] # If st_items is a list of zipcode strings. elif type(st_items) == list: zcObjects = [n for i in st_items for n in zipcode.islike(str(i))] output = [str(i).split(" ", 1)[1].split(">")[0] for i in zcObjects] else: raise ValueError("input 'st_items' must be of type str or list") return (output)
def zipcodes_list(st_items): if type(st_items) == str: zcObjects = zipcode.islike(st_items) output = [] for i in zcObjects: output.append(str(i).split(" ", 1)[1].split(">")[0]) elif type(st_items) == list: zcObjects = [] for i in st_items: zcObjects = zcObjects + zipcode.islike(i) output = [] for i in zcObjects: output.append(str(i).split(" ", 1)[1].split(">")[0]) else: raise ValueError("input 'st_items' must be of type str or list") return (output)
def zipcodes_list(st_items): zcObjects = [] for i in st_items: zcObjects = zcObjects + zipcode.islike(i) output = [] for i in zcObjects: output.append(str(i).split(" ", 1)[1].split(">")[0]) return (output)
def zipcodes_list(st_items): # (lat, lon, radius) if type(st_items) == tuple: zc_objects = zipcode.isinradius(st_items[:2], st_items[2]) output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects] # If st_items is a single zipcode string. elif type(st_items) == str: zc_objects = zipcode.islike(st_items) output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects] # If st_items is a list of zipcode strings. elif type(st_items) == list: zc_objects = [n for i in st_items for n in zipcode.islike(str(i))] output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects] else: raise ValueError("input 'st_items' must be of type str or list") return (output)
def zipcodes_list(st_items, zipcodepkg=False): print('in zipcodes list') # If st_items is a single zipcode string. if isinstance(st_items, str): # If st_items is the special keyword 'all' fetch all US zipcodes if st_items == 'all': st_items = ['0','1','2','3','4','5','6','7','8','9'] if zipcodepkg: zc_objects = [n for i in st_items for n in zipcode.islike(str(i))] else: # Fallback to uszipcode package search = SearchEngine(simple_zipcode=True) zc_objects = [] for st_item in st_items: sub_set = [n for i in st_items for n in search.by_prefix(st_item, zipcode_type='Standard', returns=50000)] zc_objects.extend(sub_set) else: if zipcodepkg: zc_objects = zipcode.islike(st_items) else: # Fallback to uszipcode package search = SearchEngine(simple_zipcode=True) zc_objects = search.by_prefix(st_items, zipcode_type='Standard', returns=50000) # If st_items is a list of zipcode strings. elif isinstance(st_items, list): if zipcodepkg: zc_objects = [n for i in st_items for n in zipcode.islike(str(i))] else: # Fallback to uszipcode package search = SearchEngine(simple_zipcode=True) zc_objects = [] for st_item in st_items: sub_set = [n for i in st_items for n in search.by_prefix(st_item, zipcode_type='Standard', returns=50000)] zc_objects.extend(sub_set) else: raise ValueError("arg 'st_items' must be of type str or list") return(zc_objects)