Add complete snitch feature with contact management, consent system, and notification delivery

This commit is contained in:
2026-02-16 20:14:03 -06:00
parent 69163a37d1
commit a6ae4e13fd
6 changed files with 810 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ from datetime import datetime, timezone, timedelta
import core.postgres as postgres
import core.notifications as notifications
import core.adaptive_meds as adaptive_meds
import core.snitch as snitch
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@@ -358,6 +359,37 @@ def check_nagging():
f"Sent nag {nag_count}/{max_nags} for {med['name']} to user {user_uuid}"
)
# Check if we should snitch (max nags reached)
should_snitch, trigger_reason, snitch_settings = (
snitch.should_snitch(
user_uuid, med_id, nag_count, missed_doses=1
)
)
if should_snitch:
logger.info(
f"Triggering snitch for {med['name']} - {trigger_reason}"
)
results = snitch.send_snitch(
user_uuid=user_uuid,
med_id=med_id,
med_name=med["name"],
nag_count=nag_count,
missed_doses=1,
trigger_reason=trigger_reason,
)
# Log results
for result in results:
if result.get("delivered"):
logger.info(
f"Snitch sent to {result['contact_name']} via {result['contact_type']}"
)
else:
logger.error(
f"Failed to snitch to {result['contact_name']}: {result.get('error')}"
)
except Exception as e:
logger.error(f"Error checking nags: {e}")