Reviewed-on: #1 Co-authored-by: mctaylors <cantsendmails@mctaylors.ru> Co-committed-by: mctaylors <cantsendmails@mctaylors.ru>
65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
import re
|
|
import requests
|
|
|
|
from typing import Any
|
|
from config import app
|
|
|
|
|
|
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) -> Any | None:
|
|
r = requests.get(f"http://{app.host}/{pathname}.json")
|
|
|
|
if r.status_code != 200:
|
|
return None
|
|
return r.json()
|