-
Notifications
You must be signed in to change notification settings - Fork 0
/
mojang_status.py
62 lines (50 loc) · 2.08 KB
/
mojang_status.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
57
58
59
60
61
62
#!/usr/bin/env python3
# ------------------------------------------------------------------------------------
# Mojang API Python scripts made by CZghost/Polda18
# Script name: Mojang Status
#
# Usage: Simply run python3 mojang_status.py
# ------------------------------------------------------------------------------------
# Import necessary libraries
#import json
from requests import get
from termcolor import colored as color
# Create payload
def main():
# This is new response
print("This service was closed down by Mojang, due to incorrect responses.")
print("Status check was made for a legacy system that is currently not up to date.")
# For historical reasons, I decided to rename the old code - it is not used anywhere
def old_main():
# Fetch data
request_url = "https://status.mojang.com/check"
response = get(request_url)
# Check response code
if(response.status_code != 200):
print(color("Couldn't check status", "red")) # Error, status couldn't be checked
exit(1)
# Deserialize response JSON
response = response.json()
# Fetch all servers from list
for row in response:
for key, value in row.items():
server = key
colorcode = value
# Decode color codes
if(colorcode == 'red'):
status = 'down'
elif(colorcode == 'yellow'):
status = 'partially down'
elif(colorcode == 'green'):
status = 'fully operational'
else:
status = 'status not available'
# If color code is anything else than traffic light colors, display white
if(colorcode != 'red' and colorcode != 'yellow' and colorcode != 'green'):
colorcode = 'white'
# Display server status
print(f"API Server `{server}`".ljust(50), end=f"status `{color(status, colorcode)}`\n")
#print(f"status `{color(status, colorcode)}`")
# Run only if fetched through main payload
if __name__ == "__main__":
main()