[WORK] v2: напоминания и синхронизация задач в Nextcloud (список «Работа»)
lint / hygiene (push) Successful in 15s
lint / hygiene (push) Successful in 15s
This commit is contained in:
1 parent
329c25b43e
commit
29b9aa1126
5 files changed
+401
-107
No files matched your search
+45
-1
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Хранилище рабочего секретаря: SQLite в /opt/work-hub/work.db."""
|
||||
"""Рабочий секретарь: хранение (задачи + напоминания)."""
|
||||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
@@ -28,10 +28,17 @@ def init():
|
||||
ts integer, text text, type text, partner text,
|
||||
due text, status text default 'inbox',
|
||||
raw_json text, done_ts integer)""")
|
||||
c.execute("""create table if not exists reminders(
|
||||
id integer primary key autoincrement,
|
||||
item_id integer, fire_at integer, text text,
|
||||
sent integer default 0, created integer)""")
|
||||
c.execute("create index if not exists idx_items_status on items(status)")
|
||||
c.execute("create index if not exists idx_items_due on items(due)")
|
||||
c.execute("create index if not exists idx_rem_fire on reminders(sent, fire_at)")
|
||||
|
||||
|
||||
# ---------- сообщения ----------
|
||||
|
||||
def log_message(room, sender, body):
|
||||
with db() as c:
|
||||
c.execute("insert into messages(ts,room,sender,body) values(?,?,?,?)",
|
||||
@@ -45,6 +52,8 @@ def recent_messages(limit=8):
|
||||
return [dict(r) for r in reversed(rows)]
|
||||
|
||||
|
||||
# ---------- задачи ----------
|
||||
|
||||
def add_item(text, parsed):
|
||||
due = parsed.get("due")
|
||||
if hasattr(due, "isoformat"):
|
||||
@@ -72,12 +81,15 @@ def update_item(item_id, fields):
|
||||
def delete_item(item_id):
|
||||
with db() as c:
|
||||
c.execute("delete from items where id=?", (item_id,))
|
||||
c.execute("delete from reminders where item_id=?", (item_id,))
|
||||
|
||||
|
||||
def set_status(item_id, status):
|
||||
with db() as c:
|
||||
c.execute("update items set status=?, done_ts=? where id=?",
|
||||
(status, now() if status == "done" else None, item_id))
|
||||
if status == "done":
|
||||
c.execute("update reminders set sent=1 where item_id=? and sent=0", (item_id,))
|
||||
|
||||
|
||||
def set_due(item_id, due):
|
||||
@@ -131,3 +143,35 @@ def stats():
|
||||
open_ = c.execute("select count(*) from items where status!='done'").fetchone()[0]
|
||||
msgs = c.execute("select count(*) from messages").fetchone()[0]
|
||||
return {"total": total, "done": done, "open": open_, "messages": msgs}
|
||||
|
||||
|
||||
# ---------- напоминания ----------
|
||||
|
||||
def add_reminder(fire_at, text, item_id=None):
|
||||
with db() as c:
|
||||
cur = c.execute(
|
||||
"insert into reminders(item_id,fire_at,text,sent,created) values(?,?,?,0,?)",
|
||||
(item_id, int(fire_at), text, now()))
|
||||
return cur.lastrowid
|
||||
|
||||
|
||||
def due_reminders():
|
||||
with db() as c:
|
||||
rows = c.execute(
|
||||
"select * from reminders where sent=0 and fire_at<=? order by fire_at limit 20",
|
||||
(now(),)).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def mark_reminder_sent(rid):
|
||||
with db() as c:
|
||||
c.execute("update reminders set sent=1 where id=?", (rid,))
|
||||
|
||||
|
||||
def pending_reminders(limit=10):
|
||||
with db() as c:
|
||||
rows = c.execute(
|
||||
"select r.*, i.text as item_text from reminders r "
|
||||
"left join items i on i.id=r.item_id "
|
||||
"where r.sent=0 order by r.fire_at limit ?", (limit,)).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
Reference in new issue
Block a user