xivstatus.py
· 1.7 KiB · Python
Raw
#!/usr/bin/env python3
import requests
from datetime import datetime, timedelta
token = ""
t = '\u2705'
f = '\u274c'
up = True
class Channel:
category = ("1063529720538484786", "status")
login = ("1063529561486270494", "status")
def get(*args, **kwargs):
if "headers" not in kwargs:
kwargs["headers"] = {}
kwargs["headers"]["Authorization"] = f"Bot {token}"
return requests.get(*args, **kwargs)
def patch(*args, **kwargs):
if "headers" not in kwargs:
kwargs["headers"] = {}
kwargs["headers"]["Authorization"] = f"Bot {token}"
return requests.patch(*args, **kwargs)
def update_channel_name(channel, status):
channel_id, name = channel
return patch("https://discord.com/api/channels/{}".format(channel_id), json={"name": status})
def a(obj):
if not isinstance(obj, bool) and str(obj.status_code)[0] != "2":
print(obj.headers)
print(obj.json())
def is_up(status):
return status in [1,2]
data = requests.get("https://is.xivup.com/indexdata").json()
up_data = [
is_up(data["Realms"]["LoginzServer"]["Status"]),
is_up(data["Realms"]["GatezServer"]["Status"]),
is_up(data["DCs"]["Materia"]),
is_up(data["Realms"]["Sophia"]["Status"])
]
if all(up_data):
a(update_channel_name(Channel.login, f"status{t}"))
else:
up = False
a(update_channel_name(Channel.login, f"status" + "".join((t if _ else f) for _ in up_data)))
time = datetime.now().strftime("%H:%M")
eorzea = datetime.utcfromtimestamp(datetime.now().timestamp()*20.571428571428573).strftime("%H:%M")
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"}))
| 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"})) |