risk3sixty / geoapi

Lightweight API service to get geolocation data from IP addresses.
https://geo.risk3sixty.com
MIT License
711 stars 39 forks source link

Include emoji in response #11

Closed jtagcat closed 1 year ago

jtagcat commented 2 years ago

It'd be neet if country was also returned with a flag of the country.

narskidan commented 1 year ago

True, this would be neat, and easy to implement as well!

On the other hand, it's really easy to get the emoji using a few lines of code, so do we really need this lib to do it for us? For example, in Python:

import flag # https://pypi.org/project/emoji-country-flag/
import requests

r = requests.get('https://geo.risk3sixty.com/me').json()
my_country_code = r['country']
my_flag = flag.flag(my_country_code)
print(f"I'm in Guatemala ({my_country_code}). Per geoapi, here's my flag: {my_flag}")

Running this script:

➜  ~ python3 country_codes.py
I'm in Guatemala (GT). According to geoapi, here's my flag: 🇬🇹

FWIW, reading the code, I see they get the IP via the NPM package, geoip-lite. This API simply serves the result of that library's lookup method verbatim.

So if you wanted such a change, maybe it would be better to propose it in the geoip-lite repo! It can be found here: https://github.com/geoip-lite/node-geoip.

They don't even need to rely on some dependency (like I did in the Python code above). You can use such a library to generate your own map of country codes to emojis, like so:

➜ ~ python3 country_codes.py
{'AD': '🇦🇩',
'AE': '🇦🇪',
'AF': '🇦🇫',
'AG': '🇦🇬',
'AI': '🇦🇮',
'AL': '🇦🇱',
'AM': '🇦🇲',
'AN': '🇦🇳',
'AO': '🇦🇴',
'AQ': '🇦🇶',
'AR': '🇦🇷',
'AS': '🇦🇸',
'AT': '🇦🇹',
'AU': '🇦🇺',
'AW': '🇦🇼',
'AX': '🇦🇽',
'AZ': '🇦🇿',
'BA': '🇧🇦',
'BB': '🇧🇧',
'BD': '🇧🇩',
'BE': '🇧🇪',
'BF': '🇧🇫',
'BG': '🇧🇬',
'BH': '🇧🇭',
'BI': '🇧🇮',
'BJ': '🇧🇯',
'BL': '🇧🇱',
'BM': '🇧🇲',
'BN': '🇧🇳',
'BO': '🇧🇴',
'BR': '🇧🇷',
'BS': '🇧🇸',
'BT': '🇧🇹',
'BV': '🇧🇻',
'BW': '🇧🇼',
'BY': '🇧🇾',
'BZ': '🇧🇿',
'CA': '🇨🇦',
'CC': '🇨🇨',
'CD': '🇨🇩',
'CF': '🇨🇫',
'CG': '🇨🇬',
'CH': '🇨🇭',
'CI': '🇨🇮',
'CK': '🇨🇰',
'CL': '🇨🇱',
'CM': '🇨🇲',
'CN': '🇨🇳',
'CO': '🇨🇴',
'CR': '🇨🇷',
'CU': '🇨🇺',
'CV': '🇨🇻',
'CX': '🇨🇽',
'CY': '🇨🇾',
'CZ': '🇨🇿',
'DE': '🇩🇪',
'DJ': '🇩🇯',
'DK': '🇩🇰',
'DM': '🇩🇲',
'DO': '🇩🇴',
'DZ': '🇩🇿',
'EC': '🇪🇨',
'EE': '🇪🇪',
'EG': '🇪🇬',
'EH': '🇪🇭',
'ER': '🇪🇷',
'ES': '🇪🇸',
'ET': '🇪🇹',
'El': '🇪🇱',
'FI': '🇫🇮',
'FJ': '🇫🇯',
'FK': '🇫🇰',
'FM': '🇫🇲',
'FO': '🇫🇴',
'FR': '🇫🇷',
'GA': '🇬🇦',
'GB': '🇬🇧',
'GD': '🇬🇩',
'GE': '🇬🇪',
'GF': '🇬🇫',
'GG': '🇬🇬',
'GH': '🇬🇭',
'GI': '🇬🇮',
'GL': '🇬🇱',
'GM': '🇬🇲',
'GN': '🇬🇳',
'GP': '🇬🇵',
'GQ': '🇬🇶',
'GR': '🇬🇷',
'GS': '🇬🇸',
'GT': '🇬🇹',
'GU': '🇬🇺',
'GW': '🇬🇼',
'GY': '🇬🇾',
'HK': '🇭🇰',
'HM': '🇭🇲',
'HN': '🇭🇳',
'HR': '🇭🇷',
'HT': '🇭🇹',
'HU': '🇭🇺',
'ID': '🇮🇩',
'IE': '🇮🇪',
'IL': '🇮🇱',
'IM': '🇮🇲',
'IN': '🇮🇳',
'IO': '🇮🇴',
'IQ': '🇮🇶',
'IR': '🇮🇷',
'IS': '🇮🇸',
'IT': '🇮🇹',
'JE': '🇯🇪',
'JM': '🇯🇲',
'JO': '🇯🇴',
'JP': '🇯🇵',
'KE': '🇰🇪',
'KG': '🇰🇬',
'KH': '🇰🇭',
'KI': '🇰🇮',
'KM': '🇰🇲',
'KN': '🇰🇳',
'KP': '🇰🇵',
'KR': '🇰🇷',
'KW': '🇰🇼',
'KY': '🇰🇾',
'KZ': '🇰🇿',
'LA': '🇱🇦',
'LB': '🇱🇧',
'LC': '🇱🇨',
'LI': '🇱🇮',
'LK': '🇱🇰',
'LR': '🇱🇷',
'LS': '🇱🇸',
'LT': '🇱🇹',
'LU': '🇱🇺',
'LV': '🇱🇻',
'LY': '🇱🇾',
'MA': '🇲🇦',
'MC': '🇲🇨',
'MD': '🇲🇩',
'ME': '🇲🇪',
'MF': '🇲🇫',
'MG': '🇲🇬',
'MH': '🇲🇭',
'MK': '🇲🇰',
'ML': '🇲🇱',
'MM': '🇲🇲',
'MN': '🇲🇳',
'MO': '🇲🇴',
'MP': '🇲🇵',
'MQ': '🇲🇶',
'MR': '🇲🇷',
'MS': '🇲🇸',
'MT': '🇲🇹',
'MU': '🇲🇺',
'MV': '🇲🇻',
'MW': '🇲🇼',
'MX': '🇲🇽',
'MY': '🇲🇾',
'MZ': '🇲🇿',
'NA': '🇳🇦',
'NC': '🇳🇨',
'NE': '🇳🇪',
'NF': '🇳🇫',
'NG': '🇳🇬',
'NI': '🇳🇮',
'NL': '🇳🇱',
'NO': '🇳🇴',
'NP': '🇳🇵',
'NR': '🇳🇷',
'NU': '🇳🇺',
'NZ': '🇳🇿',
'OM': '🇴🇲',
'PA': '🇵🇦',
'PE': '🇵🇪',
'PF': '🇵🇫',
'PG': '🇵🇬',
'PH': '🇵🇭',
'PK': '🇵🇰',
'PL': '🇵🇱',
'PM': '🇵🇲',
'PN': '🇵🇳',
'PR': '🇵🇷',
'PS': '🇵🇸',
'PT': '🇵🇹',
'PW': '🇵🇼',
'PY': '🇵🇾',
'QA': '🇶🇦',
'RE': '🇷🇪',
'RO': '🇷🇴',
'RS': '🇷🇸',
'RU': '🇷🇺',
'RW': '🇷🇼',
'SA': '🇸🇦',
'SB': '🇸🇧',
'SC': '🇸🇨',
'SD': '🇸🇩',
'SE': '🇸🇪',
'SG': '🇸🇬',
'SH': '🇸🇭',
'SI': '🇸🇮',
'SJ': '🇸🇯',
'SK': '🇸🇰',
'SL': '🇸🇱',
'SM': '🇸🇲',
'SN': '🇸🇳',
'SO': '🇸🇴',
'SR': '🇸🇷',
'SS': '🇸🇸',
'ST': '🇸🇹',
'SV': '🇸🇻',
'SY': '🇸🇾',
'SZ': '🇸🇿',
'TC': '🇹🇨',
'TD': '🇹🇩',
'TF': '🇹🇫',
'TG': '🇹🇬',
'TH': '🇹🇭',
'TJ': '🇹🇯',
'TK': '🇹🇰',
'TL': '🇹🇱',
'TM': '🇹🇲',
'TN': '🇹🇳',
'TO': '🇹🇴',
'TR': '🇹🇷',
'TT': '🇹🇹',
'TV': '🇹🇻',
'TW': '🇹🇼',
'TZ': '🇹🇿',
'UA': '🇺🇦',
'UG': '🇺🇬',
'UM': '🇺🇲',
'US': '🇺🇸',
'UY': '🇺🇾',
'UZ': '🇺🇿',
'VA': '🇻🇦',
'VC': '🇻🇨',
'VE': '🇻🇪',
'VG': '🇻🇬',
'VI': '🇻🇮',
'VN': '🇻🇳',
'VU': '🇻🇺',
'WF': '🇼🇫',
'WS': '🇼🇸',
'YE': '🇾🇪',
'YT': '🇾🇹',
'ZA': '🇿🇦',
'ZM': '🇿🇲',
'ZW': '🇿🇼'}

full script: https://gist.github.com/darighost/b38236f236bb581a4b56093ffe14fa01

Two of these are broken, but that can be fixed manually but someone with (even more) time and dedication than me.

I hope this is helpful, love this API btw.

jtagcat commented 1 year ago

Fair point.