Geoffrey-Django/MinecraftAccountInfoGrabber.py

26 lines
642 B
Python
Raw Normal View History

2018-06-03 02:42:31 +00:00
import requests
from json import JSONDecodeError
from BotErrors import UsernameLookupFailed
2018-06-03 02:42:31 +00:00
uuid_lookup_url = 'https://api.mojang.com/users/profiles/minecraft/{}'
username_lookup_url = 'https://api.mojang.com/user/profiles/{}/names'
def grab_json(url):
return requests.get(url).json()
def grab_UUID(username):
try:
player_data = grab_json(uuid_lookup_url.format(username))
return player_data['id']
except JSONDecodeError:
raise UsernameLookupFailed
2018-06-03 02:42:31 +00:00
def grab_playername(uuid):
player_data = grab_json(username_lookup_url.format(uuid))
return player_data[0]['name']