from django.conf import settings from GeoffreyApp.errors import ExternalLookupFailed import requests base_url = getattr(settings, 'GEOFFREY_MCM_BASE_URL', 'localhost') player_url = base_url + '/api/model/player/' def add_dashes_to_uuid(uuid): return '{}-{}-{}-{}-{}'.format(uuid[:8], uuid[8:12], uuid[12:16], uuid[16:20], uuid[20:]) def get_token(): api_token = getattr(settings, 'GEOFFREY_MCM_API_TOKEN') if api_token is not None: return api_token else: raise AttributeError def get_player(player_uuid): api_token = get_token() player_uuid = add_dashes_to_uuid(player_uuid) try: params = {"uuid": player_uuid, "api": api_token} j = requests.get(player_url, params=params).json() except: raise ExternalLookupFailed return j