def fetch_country_by_ip(ip):
iplookup = ipdata.ipdata()<EOL>data = iplookup.lookup(ip)<EOL>if data.get('<STR_LIT:status>') != <NUM_LIT:200>:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return data.get('<STR_LIT>', {}).get('<STR_LIT>', '<STR_LIT>')<EOL>
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