talkomatic.py 0.1.2
An easy-to-use Python versatile wrapper for the Talkomatic Bot interface ensuring best practices for making bots, and handling the REST API.
 
Loading...
Searching...
No Matches
health.py
Go to the documentation of this file.
1from talkomatic.api.v1.auth import get_auth_bot_token
2
3from requests import get as requests_get
4
5from dataclasses import dataclass
6
7
8@dataclass
10 """
11 A class representing the Talkomatic server uptime.
12
13 Args:
14 status (bool): Whether the server is up.
15 uptime (float): The uptime of the server.
16 since_timestamp (float): The timestamp of when the server was last restarted.
17 server_version (str): The version of the server.
18 """
19
20 status: bool
21 uptime: float | None
22 since_timestamp: float | None
23 server_version: str | None
24
25 @classmethod
26 def get(cls) -> "ServerHealth":
27 response = requests_get(f"https://classic.talkomatic.co/api/v1/health?token={get_auth_bot_token()}")
28 if response.status_code != 200:
29 return cls(
30 status = False,
31 uptime = None,
32 since_timestamp = None,
33 server_version = None
34 )
35 data = response.json()
36
37 return cls(
38 status = True,
39 uptime = data["uptime"],
40 since_timestamp = data["timestamp"],
41 server_version = data["version"]
42 )
43
44__all__ = ["ServerHealth"]