# Path: objects/glob.py
# 		VERSION = f.read().strip()
# 	VERSION = "Unknown"
# DATADOG_PREFIX = "peppy"


import json
import urllib.request
from common.log import logUtils as log
from objects import glob



def getCountry(ip):
	"""
	Get country from IP address using geoip api

	:param ip: IP address
	:return: country code. XX if invalid.
	"""
	try:
		# Try to get country from Pikolo Aul's Go-Sanic ip API

# Path: objects/glob.py
# 		VERSION = f.read().strip()
# 	VERSION = "Unknown"
# DATADOG_PREFIX = "peppy"


# Path: helpers/locationHelper.py
import json
import urllib.request
from common.log import logUtils as log
from objects import glob




def getCountry(ip):
	"""
	Get country from IP address using geoip api

	:param ip: IP address
	:return: country code. XX if invalid.
	"""
	try:
		# Try to get country from Pikolo Aul's Go-Sanic ip API

		result = json.loads(urllib.request.urlopen("{}/{}".format(glob.conf.config["localize"]["ipapiurl"], ip), timeout=3).read().decode())["country"]