Files
brov-macbook/ops/brovops/fmt.py
T
maksarsanjeev ac94227b94 ops: BroV Ops service for the homelab VM (tasks, subscriptions, routines)
- SQLite: tasks with subtasks and time tracking, subscriptions + payments, routines +
  history, reminder log. All rules in core.Ops (tested: ops/tests).
- brain: free text → JSON actions via the local claude CLI (Haiku, the subscription);
  only whitelisted operations are applied, nothing is deleted.
- Telegram bot (owner only): text and voice (faster-whisper on the VM), /today /tasks
  /subs /routines /stop, morning digest and daily reminders with Done/Paid/Tomorrow.
- HTTP API for BroV (bearer token): agenda, tasks, subs, routines, say, action.
- deploy/install.sh: user brovops, venv, systemd; a proxy-only mihomo (127.0.0.1:7890,
  checksum-verified) so Telegram and Claude work from Russia without a VPN on the VM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 02:45:20 +03:00

71 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Plain-text rendering for Telegram (HTML parse mode)."""
from datetime import date
from html import escape
ICON = {"task": "📌", "sub": "💳", "routine": "🔁"}
def human_day(iso: str, today: date) -> str:
d = date.fromisoformat(iso)
delta = (d - today).days
if delta == 0:
return "сегодня"
if delta == 1:
return "завтра"
if delta == -1:
return "вчера"
if delta < 0:
return f"просрочено на {-delta} дн."
return d.strftime("%d.%m")
def item_line(it: dict, today: date) -> str:
extra = f" — {it['amount']:g} {it['currency']}" if it["kind"] == "sub" else ""
client = f" [{it['client']}]" if it.get("client") else ""
return f"{ICON[it['kind']]} {escape(it['title'])}{client}{extra} · {human_day(it['date'], today)}"
def agenda(a: dict) -> str:
today = date.fromisoformat(a["today"])
out = []
if a["running"]:
out.append(f"⏱ Сейчас: <b>{escape(a['running']['title'])}</b> ({a['running']['minutes']} мин)")
for key, title in (("overdue", "🔥 Просрочено"), ("due_today", "📅 Сегодня"), ("soon", "🗓 Ближайшая неделя")):
if a[key]:
out.append(f"\n<b>{title}</b>")
out += [item_line(it, today) for it in a[key]]
if not (a["overdue"] or a["due_today"] or a["soon"]):
out.append("На ближайшую неделю ничего не горит 👌")
if a["monthly_cost"]:
out.append("\nПодписки в месяц: " + ", ".join(f"{v:g} {k}" for k, v in a["monthly_cost"].items()))
return "\n".join(out).strip()
def tree(nodes: list, depth: int = 0) -> list[str]:
out = []
for t in nodes:
mark = "⏱" if t["running"] else ("▶️" if t["status"] == "doing" else "▫️")
due = f" · до {t['due']}" if t["due"] else ""
mins = f" · {t['minutes']} мин" if t["minutes"] else ""
client = f" [{t['client']}]" if t["client"] else ""
out.append(f"{' ' * depth}{mark} #{t['id']} {escape(t['title'])}{client}{due}{mins}")
out += tree(t["children"], depth + 1)
return out
def subs(rows: list, monthly: dict, today: date) -> str:
if not rows:
return "Подписок пока нет. Скажи, например: «хостинг 900 рублей в месяц, списание 15-го»."
lines = [f"💳 {escape(s['name'])} — {s['amount']:g} {s['currency']} / "
f"{s['every'] if s['every'] > 1 else ''}{ {'day':'день','week':'нед.','month':'мес.','year':'год'}[s['period']] }"
f" · {human_day(s['next_date'], today)}" for s in rows]
lines.append("\nВ месяц: " + ", ".join(f"{v:g} {k}" for k, v in monthly.items()))
return "\n".join(lines)
def routines(rows: list, today: date) -> str:
if not rows:
return "Регламентных дел пока нет. Скажи: «бэкап NAS раз в неделю»."
return "\n".join(f"🔁 #{r['id']} {escape(r['title'])} · раз в {r['every_days']} дн. · {human_day(r['next_date'], today)}"
+ (f" · последний раз {r['last_done']}" if r["last_done"] else "") for r in rows)