2018-12-17 16:02:43 +00:00
|
|
|
from django.conf import settings
|
|
|
|
from GeoffreyApp.errors import ExternalLookupFailed
|
|
|
|
import requests
|
|
|
|
|
2019-01-04 17:20:24 +00:00
|
|
|
base_url = getattr(settings, 'GEOFFREY_MCM_BASE_URL', 'localhost')
|
2018-12-17 16:02:43 +00:00
|
|
|
|
|
|
|
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():
|
2019-01-04 17:20:24 +00:00
|
|
|
api_token = getattr(settings, 'GEOFFREY_MCM_API_TOKEN')
|
2018-12-17 16:02:43 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|