Initial commit: Handoff Pro MCP server for Kellow Construction
This commit is contained in:
30
scripts/activity_logger.py
Normal file
30
scripts/activity_logger.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Client activity logger: track views, approvals, signatures, payments."""
|
||||
import json, sys, os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
from lib.db import get_db, new_id, now, rows_to_list
|
||||
|
||||
def log(action, estimate_id=None, job_id=None, metadata=None):
|
||||
aid = new_id()
|
||||
conn = get_db()
|
||||
conn.execute("INSERT INTO client_activity (id, estimate_id, job_id, action, metadata, timestamp) VALUES (?,?,?,?,?,?)",
|
||||
(aid, estimate_id, job_id, action, json.dumps(metadata) if metadata else None, now()))
|
||||
conn.commit(); conn.close()
|
||||
return {"id": aid, "action": action, "timestamp": now()}
|
||||
|
||||
def get(estimate_id=None, job_id=None):
|
||||
conn = get_db()
|
||||
if estimate_id:
|
||||
rows = conn.execute("SELECT * FROM client_activity WHERE estimate_id=? ORDER BY timestamp DESC", (estimate_id,)).fetchall()
|
||||
elif job_id:
|
||||
rows = conn.execute("SELECT * FROM client_activity WHERE job_id=? ORDER BY timestamp DESC", (job_id,)).fetchall()
|
||||
else:
|
||||
rows = conn.execute("SELECT * FROM client_activity ORDER BY timestamp DESC LIMIT 50").fetchall()
|
||||
conn.close()
|
||||
return {"activity": rows_to_list(rows)}
|
||||
|
||||
if __name__ == "__main__":
|
||||
from lib.db import init_db; init_db()
|
||||
cmd = sys.argv[1] if len(sys.argv) > 1 else "get"
|
||||
if cmd == "log": print(json.dumps(log(sys.argv[2], estimate_id=sys.argv[3] if len(sys.argv)>3 else None)))
|
||||
elif cmd == "get": print(json.dumps(get(estimate_id=sys.argv[2] if len(sys.argv)>2 else None), indent=2))
|
||||
else: print(json.dumps({"error": f"unknown: {cmd}"}))
|
||||
Reference in New Issue
Block a user