A Python-based sentiment analysis tool that collects live headlines from leading UK news outlets (BBC News and The Guardian) and determines sentiment using a custom rule-based NLP engine.
The tool performs headline extraction, lexical scoring, classification, and visual sentiment charting.
- Live headline extraction from:
- BBC News
- The Guardian UK
- Custom-built lexicon for sentiment scoring
- Rule-based NLP pipeline (no external ML models required)
- Classification into Positive / Neutral / Negative
- Duplicate-filtering & text cleaning
- Aggregated sentiment reports per news source
- Error-handling for request failures and timeouts
- Sentiment visualization using Matplotlib (NEW)
Automatically generates a bar chart showing sentiment distribution.
- Python 3
- Requests
- BeautifulSoup (bs4)
- Collections (Counter)
- Matplotlib (for charts)
The analyzer scrapes up to 12 <h3> headlines from BBC News and The Guardian using requests and BeautifulSoup.
Headlines are lower-cased, cleaned, and spacing-normalised.
A handcrafted lexicon assigns numeric weights:
+1for each positive keyword-1for each negative keyword
Scores are mapped into one of:
- Positive
- Neutral
- Negative
The tool prints:
- Sentiment counts
- Labelled headline list
- Combined cross-source summary
- Visual sentiment chart (bar plot)
Below is an example of the visual sentiment chart generated using Matplotlib:
-
news_sentiment_analyzer.py
-
README.md
-
Integrate VADER or TextBlob for model-based sentiment scoring
-
Expand lexicon using data-driven weighting
-
Add visual sentiment charts using Matplotlib
-
Build a lightweight web interface using Flask
-
Add keyword trend detection and timeline analysis
-
Add CSV/JSON export for sentiment reports
This project is released under the MIT License.
You are free to use, modify, and distribute this software with proper attribution.