kussssh/IPO-Analyzer
0
1"""2Clear stale analysis cache for a company's doc_type.3Run from project root: python clear_analysis_cache.py4"""5import sqlite36from pathlib import Path7import tempfile, json8 9# The DB path (matches backend/config.py CACHE_DB_PATH)10CACHE_DB_PATH = Path(tempfile.gettempdir()) / "ipo_analyzer.db"11 12# ---- Also check the local backend path13LOCAL_DB = Path("backend/ipo_analyzer.db")14if LOCAL_DB.exists():15 CACHE_DB_PATH = LOCAL_DB16 17print(f"Using DB: {CACHE_DB_PATH}")18 19conn = sqlite3.connect(str(CACHE_DB_PATH))20conn.row_factory = sqlite3.Row21 22# List all companies with cached analyses23rows = conn.execute("""24 SELECT c.id, c.company_name, a.doc_type, a.updated_at,25 SUBSTR(a.result_json, 1, 120) as preview26 FROM analyses a27 JOIN companies c ON c.id = a.company_id28 ORDER BY c.company_name, a.doc_type29""").fetchall()30 31print(f"\n{'='*70}")32print(f"{'ID':>5} {'Company':<35} {'Doc':>12} {'Updated'}")33print(f"{'='*70}")34for r in rows:35 print(f"{r['id']:>5} {r['company_name'][:35]:<35} {r['doc_type']:>12} {r['updated_at'][:19] if r['updated_at'] else 'N/A'}")36 37print(f"\n{'='*70}")38target = input("\nEnter company name substring to clear (or ENTER to skip): ").strip()39if target:40 matching = [r for r in rows if target.lower() in r['company_name'].lower()]41 if not matching:42 print("No matching companies found.")43 else:44 print("\nMatching entries:")45 for r in matching:46 print(f" [{r['id']}] {r['company_name']} — {r['doc_type']}")47 48 doc_filter = input("Doc type to clear [drhp/rhp/prospectus/all]: ").strip().lower()49 confirm = input(f"Delete cache for '{target}' / '{doc_filter}'? [y/N]: ").strip().lower()50 if confirm == 'y':51 for r in matching:52 if doc_filter == 'all' or r['doc_type'] == doc_filter:53 conn.execute(54 "DELETE FROM analyses WHERE company_id = ? AND doc_type = ?",55 (r['id'], r['doc_type'])56 )57 print(f" ✓ Deleted {r['company_name']} [{r['doc_type']}]")58 conn.commit()59 print("\nCache cleared! The next analysis run will regenerate fresh results.")60 else:61 print("Aborted.")62 63conn.close()64 