Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrtye committed Jan 3, 2025
1 parent 18901fd commit 9abb557
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions apiserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,23 @@ def bytes_to_speed(bytes: int, decimal_place: int = 2) -> str:


def xui_login() -> None:
if xui_session.post(XUI_URL + "/server/status").status_code != 200:
xui_session.post(
XUI_URL + "/login",
data={"username": XUI_USERNAME, "password": XUI_PASSWORD},
)
xui_session.post(
XUI_URL + "/login",
data={"username": XUI_USERNAME, "password": XUI_PASSWORD},
)


def get_xui_status() -> dict[str, str]:
xui_login()
def get_xui_info(path_suffix: str) -> dict:
while info := xui_session.post(XUI_URL + path_suffix).status_code != 200:
xui_login()
time.sleep(10)

status = xui_session.post(XUI_URL + "/server/status")
online = xui_session.post(XUI_URL + "/xui/inbound/onlines")
return info.json()

status: dict = status.json()
online: dict[str] = online.json()

def get_xui_status() -> dict[str, str]:
status: dict = get_xui_info("/server/status")
online: dict[str] = get_xui_info("/xui/inbound/onlines")

online_count: int = len(online["obj"]) if online["obj"] else 0
online_name: str = random.choice(online["obj"]) if online_count > 0 else "-"
Expand Down

0 comments on commit 9abb557

Please sign in to comment.