Last active 1723284670

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