#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Activate repo virtualenv so python3 + deps are always found source "$SCRIPT_DIR/.venv/bin/activate" # Source .env (may override NEWS_MCP_DB_PATH) if [ -f "$SCRIPT_DIR/.env" ]; then while IFS='=' read -r key val; do # skip comments and blank lines [[ "$key" =~ ^#.*$ || -z "$key" ]] && continue # strip leading/trailing whitespace from key key="$(echo "$key" | xargs)" export "$key=$val" done < "$SCRIPT_DIR/.env" fi # Wipe everything except feed_state (which holds feed config) python3 - "$SCRIPT_DIR" <<'PYEOF' import os, sqlite3, sys from pathlib import Path script_dir = Path(sys.argv[1]) db_path = Path(os.getenv("NEWS_MCP_DB_PATH", str(script_dir / "data" / "news.sqlite"))) if not db_path.exists(): print(f"DB not found: {db_path}", file=sys.stderr) sys.exit(1) TABLES_TO_CLEAR = [ "cluster_entities", "cluster_keywords", "entity_metadata", "clusters", "meta", ] conn = sqlite3.connect(str(db_path)) for t in TABLES_TO_CLEAR: conn.execute(f"DELETE FROM {t}") conn.commit() cur = conn.execute("SELECT COUNT(*) FROM feed_state") feeds = cur.fetchone()[0] conn.close() print(f"Wiped {', '.join(TABLES_TO_CLEAR)}. feed_state rows kept: {feeds}") PYEOF