Add news pipeline: hourly scraper + Gemini summarizer in compose
Some checks failed
build-and-deploy / build (push) Failing after 4s
Some checks failed
build-and-deploy / build (push) Failing after 4s
Vendor the newsPipeline scraper + summarizer into the repo and wire them into
docker-compose against the EXISTING osint-db (no second Postgres), replacing
the upstream k8s CronJobs with in-compose wall-clock loops (:00 scrape, :05
summarize).
- news/scraper: vendored Scrapy project (257 RSS feeds) + hourly loop
scheduler (run_news_scraper.py)
- news/summerizer: vendored Gemini map-reduce summarizer, cleaned:
* fix broken google-genai response handling (_extract_text, defensive)
* fix malformed INSERT/GRANT query in save_summary_to_db
* OSINT-neutral default MAP_PROMPT; futures/markets language gated behind
INCLUDE_FUTURES=0 (yfinance lazy-imported)
* env-configurable model, batch size, lookback window
+ hourly loop scheduler (run_news_summarizer.py, :05)
- alembic 003_news: idempotent articles + article_summaries tables
- API: GET /api/news and GET /api/news/summaries (+ models, schemas)
- tests/test_api_news.py: 5 DB-backed contract tests (all pass vs real PG)
- docs/news.md + .env.example updates
Both services run under the `ingest` compose profile (matching the
ingester/camera-scraper pattern) and build arm64 on the Pi via the existing
Forgejo CI workflow. telebot left out of scope (reserved env only).
This commit is contained in:
parent
172273bed6
commit
91f436390b
27 changed files with 1772 additions and 2 deletions
71
app/main.py
71
app/main.py
|
|
@ -26,12 +26,13 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||
|
||||
from database import async_session, init_extensions
|
||||
from models import (
|
||||
alerts, documents, entities, entity_events, events, feed_sources, fires
|
||||
alerts, documents, entities, entity_events, events, feed_sources, fires,
|
||||
articles, article_summaries,
|
||||
)
|
||||
from schemas import (
|
||||
AlertCreate, AlertOut, AlertSeverity, AlertType, AlertUpdate,
|
||||
DashboardSummary, EntityCreate, EntityKind, EntityOut,
|
||||
EventCreate, EventOut, FireOut,
|
||||
EventCreate, EventOut, FireOut, NewsArticleOut, NewsSummaryOut,
|
||||
FeedSourceCreate, FeedSourceOut,
|
||||
KeyOut, KeyValueIn,
|
||||
SearchResult, SentimentSummary, SourceType,
|
||||
|
|
@ -767,6 +768,72 @@ async def camera_snapshot(camera_id: UUID):
|
|||
return Response(content=data, media_type="image/jpeg")
|
||||
|
||||
|
||||
# ── News pipeline (scraper + summarizer) ──────────────────────────────────
|
||||
# Backing data for the frontend news panel. Written by the vendored
|
||||
# news-scraper (hourly Scrapy crawl) and news-summarizer (hourly Gemini
|
||||
# map-reduce) services into the shared osint-db.
|
||||
|
||||
@app.get("/api/news", response_model=list[NewsArticleOut])
|
||||
async def list_news(
|
||||
domain: str | None = Query(
|
||||
None, description="Filter by source domain (e.g. 'www.reuters.com')"
|
||||
),
|
||||
since: datetime | None = Query(
|
||||
None,
|
||||
description="Only articles captured at/after this UTC instant "
|
||||
"(ISO 8601, e.g. '2026-08-24T12:00:00Z').",
|
||||
),
|
||||
limit: int = Query(50, ge=1, le=500),
|
||||
offset: int = Query(0, ge=0),
|
||||
):
|
||||
"""Most recent scraped news articles (newest first)."""
|
||||
async with async_session() as session:
|
||||
stmt = select(articles).order_by(
|
||||
articles.c.timestamp.desc().nullslast()
|
||||
)
|
||||
if domain:
|
||||
stmt = stmt.where(articles.c.domain == domain)
|
||||
if since:
|
||||
stmt = stmt.where(articles.c.timestamp >= since)
|
||||
stmt = stmt.limit(limit).offset(offset)
|
||||
rows = (await session.execute(stmt)).mappings().all()
|
||||
return [
|
||||
NewsArticleOut(
|
||||
id=r["id"], title=r["title"], url=r["url"],
|
||||
content=r["content"], domain=r["domain"],
|
||||
timestamp=r["timestamp"],
|
||||
)
|
||||
for r in rows
|
||||
]
|
||||
|
||||
|
||||
@app.get("/api/news/summaries", response_model=list[NewsSummaryOut])
|
||||
async def list_news_summaries(
|
||||
since: datetime | None = Query(
|
||||
None,
|
||||
description="Only summaries generated at/after this UTC instant.",
|
||||
),
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
offset: int = Query(0, ge=0),
|
||||
):
|
||||
"""Most recent master LLM summaries (newest first)."""
|
||||
async with async_session() as session:
|
||||
stmt = select(article_summaries).order_by(
|
||||
article_summaries.c.batch_timestamp.desc().nullslast()
|
||||
)
|
||||
if since:
|
||||
stmt = stmt.where(article_summaries.c.batch_timestamp >= since)
|
||||
stmt = stmt.limit(limit).offset(offset)
|
||||
rows = (await session.execute(stmt)).mappings().all()
|
||||
return [
|
||||
NewsSummaryOut(
|
||||
id=r["id"], summary_text=r["summary_text"],
|
||||
batch_timestamp=r["batch_timestamp"],
|
||||
)
|
||||
for r in rows
|
||||
]
|
||||
|
||||
|
||||
# ── Frontend ──────────────────────────────────────────────────────────────
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
|
|
|
|||
Loading…
Reference in a new issue