DEV Community

Ahmed Gulfam
Ahmed Gulfam

Posted on

Building NEWS50 AI: My CS50P Journey

Building NEWS50 AI: My CS50P Journey

Back in July, I embarked on a completely unknown voyage: CS50’s Introduction to Programming with Python (CS50P). It took me, a complete newbie to the coding world, about two months to not only complete the required assignments but also create an AI-powered news chatbot for my final project.


The Spark: Brainstorming a Real-World Idea

For my final project, I wanted to do more than create a simple program—I wanted to tackle a real-life issue.

Then a light flickered in my brain! Coming from a news-loving culture, I thought: "Why not summarize the news for busy people?"

And with that, my fingers sprang onto the keyboard.


The Engineering Pivot: API Roadblocks & Solutions

After researching extensively, I concluded that I needed two APIs: one for fetching the news and one for the AI to summarize it.

Initially, I chose GNews and Anthropic. While building my program, I frequently executed it to test the output. Suddenly, out of nowhere, I was hit by an error message.

Upon closer review, I learned that Anthropic APIs could only be used on a free trial; after that, cash speaks! I didn't want to spend money on an API for a learning project, so plans changed. I pivoted to Gemini, which offers generous usage limits for developers. Great! We were back on track.


How NEWS50 AI Works

After a couple of days of hitting the keyboard, the project was ready!

The program welcomes the user with a splendid banner: "Welcome to NEWS50 AI". From there, the user is asked to select a category such as World, Business, or Sports.

Key Features:

  • Smart News Search: If the user enters a specific topic (ranging from "La Liga fixtures" to "Who is the oldest man alive?"), the AI first browses through news articles for relevant keywords.
  • Graceful Fallback: If it doesn't find news articles matching the query, it shifts to the wide world of the internet to search through it directly.
  • User-Friendly Output: It returns the collected information in clear, easy-to-read language.
  • Simple Exit: Typing leave safely terminates the program.

Try It Out

You can find full details and personally test my program on GitHub:

NEWS50 AI

Want to read the news but you are busy? Say hello to NEWS50 AI; an interactive chatbot that delivers real-time news summaries and answers all of your questions. Instead of scrolling through endless news articles and websites, you can simply choose from a category, such as World, Business, Sports etc to get a clean, legible and AI-generated summary of whatever is happening around the world.

The project revolves around 2 APIs: GNews and Google Gemini GNews gives the real-time news data while Google Gemini summarizes it into a user-friendly way.

Video Link:

Files:

.
├── project.py          # Main file that delivers the latest news
├── test_project.py     # Unit tests for key functions in project.py
├── requirements.txt    # List of required libraries
└── README.md           # This file

How It Works:

The program welcomes you with a captivating ASCII banner, imported from pyfiglet, followed by a couple of introductory…

Top comments (0)