Last active 1715060792

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

Revision 9a079954ef87050eb98726a1245a2640dd04673f

xivstatus.py Raw
1#!/usr/bin/env python3
2import requests
3from datetime import datetime, timedelta
4
5t = '\u2705'
6f = '\u274c'
7up = True
8
9class Channel:
10 category = ("1063529720538484786", "status")
11 login = ("1063529561486270494", "status")
12
13def 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
19def 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
25def 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
29def a(obj):
30 if not isinstance(obj, bool) and str(obj.status_code)[0] != "2":
31 print(obj.headers)
32 print(obj.json())
33
34def is_up(status):
35 return status in [1,2]
36
37data = requests.get("https://is.xivup.com/indexdata").json()
38up_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
45if all(up_data):
46 a(update_channel_name(Channel.login, f"status{t}"))
47else:
48 up = False
49 a(update_channel_name(Channel.login, f"status" + "".join((t if _ else f) for _ in up_data)))
50
51time = datetime.now().strftime("%H:%M")
52eorzea = datetime.utcfromtimestamp(datetime.now().timestamp()*20.571428571428573).strftime("%H:%M")
53a(patch("https://discord.com/api/channels/{}".format(Channel.category[0]), json={"name": (f"{f}-" if not up else "")+ f"status-{time}-AEST-{eorzea}-ET"}))