-
Notifications
You must be signed in to change notification settings - Fork 0
/
mojang_username_to_uuid.py
56 lines (45 loc) · 1.57 KB
/
mojang_username_to_uuid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# ------------------------------------------------------------------------------------
# Mojang API Python scripts made by CZghost/Polda18
# Script name: Mojang Status
#
# Usage: Simply run python3 mojang_username_to_uuid.py <username>
# ------------------------------------------------------------------------------------
# Import necessary libraries
#import json
from requests import get
from termcolor import colored as color
import sys
import uuid
# Create payload
def main():
# Check given arguments (only 1 accepted, ignore rest)
if(len(sys.argv) < 2):
print("No argument given.")
exit(1)
# Fetch data
username = sys.argv[1]
request_url = f"https://api.mojang.com/users/profiles/minecraft/{username}"
response = get(request_url)
# Check response code
if(response.status_code != 200):
print(color("Invalid entry or profile doesn't exist", "red"))
exit(2)
# Deserialize response JSON
response = response.json()
# Fetch username and UUID
username = response["name"]
try:
useruuid = uuid.UUID(response["id"])
except:
print(color('Retrieved UUID is invalid.', 'red')) # Some error occured, retrieved UUID cannot be decoded
exit(3)
# Display data
print("Username".ljust(20), end="UUID\n")
#print("UUID")
print("--------------------------------------------------------")
print(username.ljust(20), end=f'{useruuid}\n')
#print(useruuid)
# Run only if fetched through main payload
if __name__ == '__main__':
main()