All checks were successful
Build / Upload to production (push) Successful in 1m38s
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
import re
|
|
import requests
|
|
|
|
from typing import Any, Optional
|
|
import config
|
|
|
|
|
|
def humanize_tags_from_json(value: str, default: str) -> str:
|
|
if value != "":
|
|
return ", ".join([re.sub("_\\(.*", "", t) for t in value.split()])
|
|
return default
|
|
|
|
|
|
def humanize_filesize(value: int) -> str:
|
|
for unit in ["B", "KiB", "MiB", "GiB"]:
|
|
if value < 1024 or unit == "GiB":
|
|
break
|
|
value /= 1024
|
|
return f"{value:.2f} {unit}"
|
|
|
|
|
|
def format_rating(value: str) -> str | None:
|
|
match value:
|
|
case "g":
|
|
# Negative Squared Latin Capital Letter G
|
|
return "๐
ถ"
|
|
case "s":
|
|
# Negative Squared Latin Capital Letter S
|
|
return "๐"
|
|
case "q":
|
|
# Negative Squared Latin Capital Letter Q
|
|
return "๐"
|
|
case "e":
|
|
# Negative Squared Latin Capital Letter E
|
|
return "๐
ด"
|
|
return None
|
|
|
|
|
|
def format_status(data) -> str:
|
|
is_active = True
|
|
is_pending = data["is_pending"]
|
|
is_flagged = data["is_flagged"]
|
|
is_deleted = data["is_deleted"]
|
|
is_banned = data["is_banned"]
|
|
if is_pending | is_flagged | is_deleted:
|
|
is_active = False
|
|
|
|
status = []
|
|
if is_active:
|
|
status.append("Active")
|
|
if is_pending:
|
|
status.append("Pending")
|
|
if is_flagged:
|
|
status.append("Flagged")
|
|
if is_banned:
|
|
status.append("Banned")
|
|
return " ".join(status)
|
|
|
|
|
|
def get_json(pathname: str, query: Optional[list] = None) -> Any | None:
|
|
url = [f"http://{config.app.host}/{pathname}.json"]
|
|
if query is not None:
|
|
url.append("?")
|
|
url.append("&".join(query))
|
|
r = requests.get("".join(url))
|
|
|
|
if r.status_code != 200:
|
|
return None
|
|
return r.json()
|