A simple Python command-line tool that fetches recent news articles based on a search query using NewsAPI and summarizes the article content using extractive summarization. You can also save the summaries to a text file.
Built for my CS50P final project.
- Fetch latest news articles using a keyword
- Automatically generate summaries using the
summaNLP library - Display capitalized article titles
- Show summary word count
- Option to save results in a text file
- Built-in unit tests using
pytest
Install the dependencies from requirements.txt:
pip install -r requirements.txtContents of requirements.txt:
requests
python-dotenv
summa
pytestSign up at https://newsapi.org/ to get your free API key.
Create a .env file in the root directory:
NEWS_API_KEY=your_api_key_here
python project.py <search_query>Example:
python project.py technologyFor multi-word search queries, enclose them in single quotes ('<search_query>') or double quotes ("<search_query>")
Example:
python project.py "artificial intelligence"You'll be prompted to enter the number of articles you want to fetch and whether you want to save the results.
To run tests for the summarization, word count, and capitalization logic:
pytest test_project.py- Uses the NewsAPI to fetch articles related to the search query.
- Summarizes the article content using the
summalibrary. Filters unwanted outputs (like the default error).
- Counts and returns the number of words in the summary.
- Converts article titles to uppercase.
- Saves the article title and summary to a
.txtfile with formatting.
project.py # Main script
test_project.py # Unit tests for helper functions
.env # Stores your API key (not checked into version control)
requirements.txt # Dependencies
summaries.txt # Optional output file where summaries are saved
1. AI IS CHANGING THE WORLD
OVERSIMPLIFIED:
Artificial Intelligence continues to revolutionize global industries...
45 words
Would you like to save this in a text file? (y/n): y
- Add a text-to-speech (tts) feature
- Save summaries in a custom filename and type as per user's choice
- Support for multiple languages instead of just English
- Shifting from CLI to web-based interface using
Flaskor an app-like GUI usingtkinter
Feel free to recommend more features or optimizations or better tests!
MIT License. Feel free to fork, modify, and use it in your own projects.
