def fetch_country_by_ip(ip):
    """
    Fetches country code by IP

    Returns empty string if the request fails in non-200 code.

    Uses the ipdata.co service which has the following rules:

    * Max 1500 requests per day

    See: https://ipdata.co/docs.html#python-library
    """
    iplookup = ipdata.ipdata()
    data = iplookup.lookup(ip)
    if data.get('status') != 200:
        return ''

    return data.get('response', {}).get('country_code', '')
def fetch_country_by_ip ( ip ) : iplookup = ipdata . ipdata ( ) data = iplookup . lookup ( ip ) if data . get ( 'status' ) != 200 : return '' return data . get ( 'response' , { } ) . get ( 'country_code' , '' )
Fetches country code by IP

    Returns empty string if the request fails in non-200 code.

    Uses the ipdata.co service which has the following rules:

    * Max 1500 requests per day

    See: https://ipdata.co/docs.html#python-library