Political News Sentiment Scorer

A tracker for how New Zealand's news media covers each political party in the run-up to the 2026 general election. It scrapes the major NZ outlets every two hours, scores the tone of each article toward every party, and charts the results over time.

Polsent media tone chart: per-party sentiment over 90 days with election events marked, above a row of latest 7-day tone scores
The dashboard leads with one chart: per-party media tone over time, with election events marked and the latest 7-day score for each party beneath it.

Tech Stack

  • ·Frontend: React 18 with TypeScript on Vite. The main chart uses Recharts and the weekly heatmap is hand-drawn SVG. Routing is hash-based for easy embedding. Deployed on Vercel.
  • ·Backend: ASP.NET Core on .NET 9 in C#, with Entity Framework Core. PostgreSQL on Railway. Scheduled scraping runs on Quartz, and Swagger is exposed for API exploration.

How It Works

Quartz runs the pipeline every two hours. The scraper pulls articles from eleven NZ outlets, including RNZ, Stuff, NZ Herald, The Spinoff and Newsroom, through a mix of RSS and HTML scraping. Duplicate URLs are skipped, so the job is safe to rerun.

Each article gets two scores. The first comes from a hand-built dictionary of weighted sentiment words with negation and intensifiers, so 'not praised' flips negative and 'strongly praised' scores higher than 'praised'. The second comes from a RoBERTa sentiment model running in-process with ONNX Runtime. It started on the HuggingFace API, and I tried FinBERT for a few months before going back to RoBERTa, because FinBERT read most political text as neutral. When the free API allowance ran out in October, I moved the model in-process. The two scores blend 65% model, 35% dictionary.

Scores are worked out per party, not per article. Only the sentences that mention a party count as evidence about it, and in a sentence like 'National slams Labour' the evidence goes against Labour, not National. Party and politician names are matched with word-boundary regex, which stops 'national park' counting as the National Party or 'green energy' as the Greens.

Opinion pieces, columns and poll stories are filtered out, because their tone belongs to the writer or the public rather than the coverage. The frontend shows a 7-day average per party with election events marked on the timeline, the latest score for each party, and a week-by-week heatmap. Once collection ends, a script downloads every chart's data into static JSON so the backend can be shut down and the site keeps working.

Week-by-week heatmap of media tone for each party in seven shades of grey, dark for negative and light for positive
Week by week: each cell is a party's average tone for that week. Hatched cells had too few articles to score, and outlined cells had none.

Decisions

  • ·Regex over NLP for entity detection: fast, predictable, and the word boundaries kill the obvious false positives.
  • ·Quartz on a 2-hour cron: the data keeps itself current without me touching it, and the same logic can be triggered manually for backfills.
  • ·Targeted tests on the parts most likely to be wrong: the lexicon and the entity matcher, since those drive every number in the app.