Skip to content

Issue 3 (Trending topics service: robustness + offline mode + source options) #2

Description

@abby-ql

Owner:

What’s already done: app/core/trends.py already supports NewsAPI or RSS fallback; extraction logic exists; DB stores TrendTopic.

Goal: Make trends ingestion reliable for demo + backtesting without needing live APIs.

Tasks

  • Add offline ingest mode:

    • if TRENDS_SOURCE=snapshot, load data/trends_snapshot_today.json and store it as TrendTopic rows
  • Improve extraction determinism:

    • ensure stable sorting (volume desc, tie-break alphabetical)
    • filter out obvious generic terms with config (move drop list into config file)
  • Optional (nice to have): add GOV.UK Atom feed option as an alternative open-licensed UK source

Acceptance criteria

  • POST /trends/ingest works in 3 modes:

    1. RSS default
    2. NewsAPI if key present
    3. Snapshot mode with no network
  • GET /trends/current returns consistent, sorted list

Tests

  • Unit test: extract_trend_terms() deterministically returns same top terms given a fixed input headline list
  • Integration-ish test: snapshot ingest populates DB and endpoint returns them

Dependencies

  • None (snapshot mode avoids any key/network dependency)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions