symerio / pgeocode

Postal code geocoding and distance calculation
https://pgeocode.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
238 stars 58 forks source link

Fix PC encoding for Brazil #36

Open willidert opened 4 years ago

willidert commented 4 years ago

The geonames does not work for all CEPs in Brazil. I added a function that checks if the zip code is valid for geonames.

Closes https://github.com/symerio/pgeocode/issues/30

rth commented 4 years ago

Thanks @willidert . We could add optional validation via the query_postal_code(..., validate=True) parameter, however it would need to be extensively tested to pass on all postal codes in the DB and fail on a few counter examples (see test_pgeocode.py for examples of test).

For now this is a 1 file package (pgeocode.py) with test_pgeocode.py for unit tests. So this PR should only change these two files.

To fix merge conflicts please use back see https://github.com/symerio/pgeocode/blob/master/doc/contributing.rst#code-style for more details.

rth commented 4 years ago

Also if we want to do this check, the mechanism needs to be generic enough so it can be easily extended to other countries. Maybe something like,

class _CheckPostalCode:
    def __init__(self, country):
        self.country = country

    def __call__(self, postal_code):
        if self.country == "BR":
           ...
        else:
           raise NotImplementedError
willidert commented 4 years ago

hi @rth , i've been a little busy, sorry. I'll make the changes. Thank you very much for the suggestions and support.

willidert commented 4 years ago

Sorry, i have problems with github actions.

willidert commented 4 years ago

Thx for the opportunity, I hope it helped. I had a little difficulty in the tests. I'm sorry if something is strange. I am available for any correction.