def find_near_zips(zipc, city, state): x = zipcodes.similar_to(zipc[0], zips=zipcodes.filter_by(zipcodes.list_all(), active=True, city= city, state = state)) zipps = [] for zips in x: zipps.append(zips['zip_code']) return zipps
def test_matching(self): self.assertEqual( zipcodes.similar_to("10001"), [{ "zip_code": "10001", "zip_code_type": "STANDARD", "city": "NEW YORK", "state": "NY", "lat": 40.71, "long": -73.99, "world_region": "NA", "country": "US", "active": True, }], )
def test_similar_to(self): self.assertEqual( zipcodes.similar_to("0643"), [ { "zip_code": "06437", "zip_code_type": "STANDARD", "city": "GUILFORD", "state": "CT", "lat": 41.28, "long": -72.67, "world_region": "NA", "country": "US", "active": True, }, { "zip_code": "06438", "zip_code_type": "STANDARD", "city": "HADDAM", "state": "CT", "lat": 41.45, "long": -72.5, "world_region": "NA", "country": "US", "active": True, }, { "zip_code": "06439", "zip_code_type": "PO BOX", "city": "HADLYME", "state": "CT", "lat": 41.4, "long": -72.34, "world_region": "NA", "country": "US", "active": True, }, ], )
pd.get(url) time.sleep(0.1) name = fake.name() first = name.split(' ')[0] last = name.split(' ')[1] textnows = [] index = str(randint(0, 500)) i = str(randint(0, 500)) p = fake.color_name() + index u = (name.split(' ')[0] + name.split(' ')[1] + index).replace(".", "") e = first + last + '+' + index + '@gmail.com' z = str(randint(0, 9)) y = str(randint(0, 9)) length = len(zipcodes.similar_to(y + z)) random = (randint(0, length)) zipIn = zipcodes.similar_to(y + z)[random]['zip_code'] cityIn = zipcodes.similar_to(y + z)[random]['city'] stateIn = zipcodes.similar_to(y + z)[random]['state'] prof = " ".join(fake.words(nb=3, ext_word_list=None, unique=True)) para = fake.paragraph(nb_sentences=5, variable_nb_sentences=True, ext_word_list=None) para2 = fake.paragraph(nb_sentences=5, variable_nb_sentences=True, ext_word_list=None) para3 = fake.paragraph(nb_sentences=5, variable_nb_sentences=True, ext_word_list=None) description2 = (para + '\n\n' + para2 + '\n\n' + para3)
def main(): # name of this stage, typically a name to reference the assertion # assertion: lambda which returns unittest callable with self's (testcase's) context # predicates: lambda or sequence of lambdas to call and pass to the assertion unittests_schema = [ { "name": "true", "assertion": lambda self: self.assertTrue, "predicates": [ lambda: zipcodes.is_real("06905"), lambda: zipcodes._contains_nondigits("1234a"), # bad length lambda: callable_raise_exc( lambda: zipcodes._clean("000000"), ValueError ), # bad characters lambda: callable_raise_exc( lambda: zipcodes._clean("0000a"), ValueError ), # ensure zips argument works lambda: len( zipcodes.similar_to( "2", zips=zipcodes.filter_by(active=True, city="Windsor") ) ) == 3, ], }, { "name": "false", "assertion": lambda self: self.assertFalse, "predicates": [ lambda: zipcodes.is_real("91239"), # digits and "-" are acceptable lambda: zipcodes._contains_nondigits("12345"), lambda: zipcodes._contains_nondigits("1234-"), ], }, { "name": "equal", "assertion": lambda self: self.assertEqual, "predicates": [ # valid_zipcode_length parameter (lambda: zipcodes._clean("0646", 4), lambda: "0646"), # default behavior (lambda: zipcodes._clean("06469"), lambda: "06469"), (lambda: zipcodes.list_all(), lambda: zipcodes._zips), ( lambda: zipcodes.filter_by(city="Old Saybrook"), lambda: [ { "zip_code": "06475", "zip_code_type": "STANDARD", "active": True, "city": "Old Saybrook", "acceptable_cities": [], "unacceptable_cities": ["Fenwick"], "state": "CT", "county": "Middlesex County", "timezone": "America/New_York", "area_codes": ["860"], "world_region": "NA", "country": "US", "lat": "41.3015", "long": "-72.3879", } ], ), ( lambda: zipcodes.similar_to("1018"), lambda: [ { "acceptable_cities": [], "active": False, "area_codes": ["212"], "city": "New York", "country": "US", "county": "New York County", "lat": "40.71", "long": "-74", "state": "NY", "timezone": "America/New_York", "unacceptable_cities": ["J C Penney"], "world_region": "NA", "zip_code": "10184", "zip_code_type": "UNIQUE", }, { "acceptable_cities": [], "active": True, "area_codes": ["212"], "city": "New York", "country": "US", "county": "New York County", "lat": "40.7143", "long": "-74.0067", "state": "NY", "timezone": "America/New_York", "unacceptable_cities": [], "world_region": "NA", "zip_code": "10185", "zip_code_type": "PO BOX", }, ], ), ( lambda: zipcodes.similar_to("1005"), lambda: [ { "zip_code": "10055", "zip_code_type": "STANDARD", "active": True, "city": "New York", "acceptable_cities": [], "unacceptable_cities": ["Manhattan"], "state": "NY", "county": "New York County", "timezone": "America/New_York", "area_codes": ["212"], "world_region": "NA", "country": "US", "lat": "40.7579", "long": "-73.9743", } ], ), ( lambda: zipcodes.similar_to("10001"), lambda: [ { "zip_code": "10001", "zip_code_type": "STANDARD", "active": True, "city": "New York", "acceptable_cities": [], "unacceptable_cities": [ "Empire State", "G P O", "Greeley Square", "Macys Finance", "Manhattan", ], "state": "NY", "county": "New York County", "timezone": "America/New_York", "area_codes": ["718", "917", "347", "646"], "world_region": "NA", "country": "US", "lat": "40.7508", "long": "-73.9961", } ], ), ], }, ] generate_unittests(unittests_schema) logger.info("Zipcodes version: {}".format(zipcodes.__version__)) unittest.main()