Search code examples
pythonlocation

Python - check if given zip code (or city) is in Czech Republic


I am to do some address verifications on our company database and problem is that there is another 97 or so countries apart from Czech Republic. They are quite a minority and there is no need to verificate them. Still I need to somehow set them apart, because the API I am currently using for verification can send me only response that it wasn't found.

So I am looking for some tool to recognise Czech ZIP code, or city, etc. In python.


Solution

  • So I found the answer myself.

    I can distinguish from what state selected address is thanks to geopy library.

    Input:

    from geopy.geocoders import Nominatim
    
    geolocator = Nominatim(user_agent="geoapiExercises")
    location = geolocation.geocode('city-name')
    print(location.address)
    

    output (in case city-name == Brno):

    Brno, okres Brno-město, Jihomoravský kraj, Jihovýchod, Česko
    

    Also I found out, that you can insert another coutry city names in your language and it will find it anyway and that is quite handy.

    output (in case city-name == Mníchov):

    München, Bayern, Deutschland