Last active 1715060792

A script that runs (for me) every 5 minutes, updating category and channel names to indicate FFXIV server status

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

1 file changed, 53 insertions

xivstatus.py(file created)

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