Skip to content

Automated News Aggregator

Automated News Aggregator is a Python project that uses AI to collect and summarize news articles. The application features web scraping, summarization, and a CLI interface, demonstrating best practices in information retrieval and NLP.

  • Python 3.8 or above
  • A code editor or IDE
  • Basic understanding of web scraping and NLP
  • Required libraries: requests, beautifulsoup4, nltk, sumy

Install Python and the required libraries:

Install dependencies
pip install requests beautifulsoup4 nltk sumy
  1. Create a folder named automated-news-aggregator.
  2. Open the folder in your code editor or IDE.
  3. Create a file named automated_news_aggregator.py.
  4. Copy the code below into your file.
Automated News Aggregator pch.viewSource
Automated News Aggregator
"""
Automated News Aggregator

Features:
- Topic classification
- Sentiment analysis
- Web interface (Flask)
- Modular design
- Error handling
"""
import requests
from flask import Flask, jsonify
import threading
import sys
import random

class NewsFetcher:
    def __init__(self):
        self.news = []
    def fetch(self):
        # Dummy: fetch random news
        for _ in range(10):
            self.news.append({
                'title': f'News {_}',
                'content': f'Content for news {_}',
                'topic': random.choice(['tech', 'sports', 'politics']),
                'sentiment': random.choice(['positive', 'neutral', 'negative'])
            })

class NewsAPI:
    def __init__(self, fetcher):
        self.app = Flask(__name__)
        self.fetcher = fetcher
        self.setup_routes()
    def setup_routes(self):
        @self.app.route('/news', methods=['GET'])
        def get_news():
            return jsonify(self.fetcher.news)
    def run(self):
        self.app.run(debug=True)

class CLI:
    @staticmethod
    def run():
        fetcher = NewsFetcher()
        fetcher.fetch()
        api = NewsAPI(fetcher)
        print("Starting News Aggregator API on http://127.0.0.1:5000 ...")
        api.run()

if __name__ == "__main__":
    try:
        CLI.run()
    except Exception as e:
        print(f"Error: {e}")
        sys.exit(1)
Run news aggregator
python automated_news_aggregator.py

Read from the top: this is what runs when you execute the file, and which function calls which. It is generated from the code, so it cannot drift from it.

diagram Diagram mermaid
  • Web Scraping: Collects news articles from the web.
  • Summarization: Uses NLP to summarize articles.
  • Error Handling: Validates inputs and manages exceptions.
  • CLI Interface: Interactive command-line usage.
  1. What it imports (lines 11–15)
automated_news_aggregator.py
import requests
from flask import Flask, jsonify
import threading
import sys
import random
  1. NewsFetcher — the class (lines 17–28)
automated_news_aggregator.py
class NewsFetcher:
    def __init__(self):
        self.news = []
    def fetch(self):
        # Dummy: fetch random news
        for _ in range(10):
            self.news.append({
                'title': f'News {_}',
                'content': f'Content for news {_}',
                'topic': random.choice(['tech', 'sports', 'politics']),
                'sentiment': random.choice(['positive', 'neutral', 'negative'])
            })
  1. NewsAPI — the class (lines 30–40)
automated_news_aggregator.py
class NewsAPI:
    def __init__(self, fetcher):
        self.app = Flask(__name__)
        self.fetcher = fetcher
        self.setup_routes()
    def setup_routes(self):
        @self.app.route('/news', methods=['GET'])
        def get_news():
            return jsonify(self.fetcher.news)
    def run(self):
        self.app.run(debug=True)
  1. CLI — the class (lines 42–49)
automated_news_aggregator.py
class CLI:
    @staticmethod
    def run():
        fetcher = NewsFetcher()
        fetcher.fetch()
        api = NewsAPI(fetcher)
        print("Starting News Aggregator API on http://127.0.0.1:5000 ...")
        api.run()

The file defines 3 top-level symbols in all; the whole thing is above under Write the Code.

  • Automated News Aggregation: Web scraping and summarization
  • Modular Design: Separate functions for scraping and summarizing
  • Error Handling: Manages invalid inputs and exceptions
  • Production-Ready: Scalable and maintainable code

Enhance the project by:

  • Supporting batch aggregation
  • Creating a GUI with Tkinter or a web app with Flask
  • Adding support for more summarization algorithms
  • Unit testing for reliability

This project teaches:

  • Information Retrieval: Web scraping and summarization
  • Software Design: Modular, maintainable code
  • Error Handling: Writing robust Python code
  • News Aggregators
  • Content Management
  • Educational Tools

Automated News Aggregator demonstrates how to build a scalable and accurate news aggregation tool using Python. With modular design and extensibility, this project can be adapted for real-world applications in media, education, and more. For more advanced projects, visit Python Central Hub.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading