seanpianka / Zipcodes

A simple library for querying U.S. zipcodes.
MIT License
78 stars 15 forks source link

Is there a way to get all zip-codes in a given area ? #11

Closed UGuntupalli closed 4 years ago

UGuntupalli commented 4 years ago

@seanpianka : Thank you for the effort to compile this package. I just ran into it today as I was exploring a problem:

   import zipcodes 
   from pprint import pprint 
  1. Approach # 1
    pprint(zipcodes.matching('11'))
  2. Approach # 2
    pprint(zipcodes.filter_by(city="New York"))

    While approach 2 gives a result, it is not what I seek. Is there a method to achieve this ?

seanpianka commented 4 years ago

Use similar_to instead of matching:

pprint(zipcodes.similar_to('11'))

matching looks up the information for the specific zipcode you provide, matching the exact argument. similar_to will search for all zipcodes which begin with the prefix "11".

Also, why is approach #2 not what you're looking for? That should return all of the zip codes where city == "New York".

UGuntupalli commented 4 years ago

@seanpianka : Thank you for the quick response. Here is what I tried:

   import zipcodes 
   from pprint import pprint 

   t = zipcodes.filter_by(city="Long Island")
   # t is a list of 3 items. Long Island has 8 zip codes - if I am not wrong. https://www.zip- codes.com/city/ny-long-island-city.asp

I am trying similar_to() and I will let you know if I run into any trouble.

seanpianka commented 4 years ago

I'm closing this issue now, but feel free to re-open.