Last active 1723284670

aly's Avatar aly revised this gist 1723284670. Go to revision

1 file changed, 54 insertions

xivstatus.py(file created)

@@ -0,0 +1,54 @@
1 + #!/usr/bin/env python3
2 + import requests
3 + from datetime import datetime, timedelta
4 +
5 + token = ""
6 + t = '\u2705'
7 + f = '\u274c'
8 + up = True
9 +
10 + class Channel:
11 + category = ("1063529720538484786", "status")
12 + login = ("1063529561486270494", "status")
13 +
14 + def get(*args, **kwargs):
15 + if "headers" not in kwargs:
16 + kwargs["headers"] = {}
17 + kwargs["headers"]["Authorization"] = f"Bot {token}"
18 + return requests.get(*args, **kwargs)
19 +
20 + def patch(*args, **kwargs):
21 + if "headers" not in kwargs:
22 + kwargs["headers"] = {}
23 + kwargs["headers"]["Authorization"] = f"Bot {token}"
24 + return requests.patch(*args, **kwargs)
25 +
26 + def update_channel_name(channel, status):
27 + channel_id, name = channel
28 + return patch("https://discord.com/api/channels/{}".format(channel_id), json={"name": status})
29 +
30 + def a(obj):
31 + if not isinstance(obj, bool) and str(obj.status_code)[0] != "2":
32 + print(obj.headers)
33 + print(obj.json())
34 +
35 + def is_up(status):
36 + return status in [1,2]
37 +
38 + data = requests.get("https://is.xivup.com/indexdata").json()
39 + up_data = [
40 + is_up(data["Realms"]["LoginzServer"]["Status"]),
41 + is_up(data["Realms"]["GatezServer"]["Status"]),
42 + is_up(data["DCs"]["Materia"]),
43 + is_up(data["Realms"]["Sophia"]["Status"])
44 + ]
45 +
46 + if all(up_data):
47 + a(update_channel_name(Channel.login, f"status{t}"))
48 + else:
49 + up = False
50 + a(update_channel_name(Channel.login, f"status" + "".join((t if _ else f) for _ in up_data)))
51 +
52 + time = datetime.now().strftime("%H:%M")
53 + eorzea = datetime.utcfromtimestamp(datetime.now().timestamp()*20.571428571428573).strftime("%H:%M")
54 + a(patch("https://discord.com/api/channels/{}".format(Channel.category[0]), json={"name": (f"{f}-" if not up else "")+ f"status-{time}-AEST-{eorzea}-ET"}))
Newer Older