nanobot: 2026-09-14 21:07:55 — usage: resets countdown + per-model list
This commit is contained in:
@@ -8,6 +8,7 @@ import os
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
|
||||
API_URL = "https://ollama.com/api/usage"
|
||||
@@ -30,8 +31,31 @@ def load_api_key() -> str:
|
||||
def fmt_models(models: list[dict]) -> str:
|
||||
if not models:
|
||||
return ""
|
||||
parts = [f'{m["name"]} ({m["request_count"]} req)' for m in models]
|
||||
return ", ".join(parts)
|
||||
return ", ".join(f'{m["name"]} ({m["request_count"]})' for m in models)
|
||||
|
||||
|
||||
def until_next_full_hour(now: datetime) -> timedelta:
|
||||
nxt = (now.replace(minute=0, second=0, microsecond=0)
|
||||
+ timedelta(hours=1))
|
||||
return nxt - now
|
||||
|
||||
|
||||
def until_next_monday(now: datetime) -> timedelta:
|
||||
# days until Monday (weekday(): Mon == 0)
|
||||
days = (7 - now.weekday()) % 7 or 7
|
||||
nxt = (now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
+ timedelta(days=days))
|
||||
return nxt - now
|
||||
|
||||
|
||||
def fmt_delta_short(td: timedelta) -> str:
|
||||
"""Human countdown, dashboard style: '1 hour', '55 minutes', '6 days'."""
|
||||
total = td.total_seconds()
|
||||
if total >= 86400:
|
||||
return f"{int(total // 86400)} days"
|
||||
if total >= 3600:
|
||||
return f"{round(total / 3600)} hours"
|
||||
return f"{max(1, round(total / 60))} minutes"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@@ -50,22 +74,27 @@ def main() -> None:
|
||||
limits = data.get("limits", {})
|
||||
session = limits.get("session", {})
|
||||
weekly = limits.get("weekly", {})
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
print("Ollama Cloud — spotřeba")
|
||||
s_models = fmt_models(session.get("models", []))
|
||||
print(f'Session: {session.get("usage", 0) * 100:.1f} %' + (f" — {s_models}" if s_models else ""))
|
||||
print(
|
||||
f'Session: {session.get("usage", 0) * 100:.1f} %, '
|
||||
f'resets in {fmt_delta_short(until_next_full_hour(now))}'
|
||||
+ (f" — {s_models}" if s_models else "")
|
||||
)
|
||||
w_models = fmt_models(weekly.get("models", []))
|
||||
print(f'Weekly: {weekly.get("usage", 0) * 100:.1f} %' + (f" — {w_models}" if w_models else ""))
|
||||
print(
|
||||
f'Weekly: {weekly.get("usage", 0) * 100:.1f} %, '
|
||||
f'resets in {fmt_delta_short(until_next_monday(now))}'
|
||||
+ (f" — {w_models}" if w_models else "")
|
||||
)
|
||||
|
||||
activity = data.get("activity", {})
|
||||
cost = activity.get("cost")
|
||||
if cost is not None:
|
||||
period = activity.get("period", {})
|
||||
print(
|
||||
f'Aktivita: ${float(cost):.5f}'
|
||||
f' ({period.get("type", "?")} {period.get("starting_at", "")[:10]}'
|
||||
f' → {period.get("ending_at", "")[:10]})'
|
||||
)
|
||||
models = weekly.get("models", [])
|
||||
if models:
|
||||
print("Modely (počet požadavků, weekly okno):")
|
||||
for m in models:
|
||||
print(f' {m["name"]}: {m["request_count"]}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user