Skip to main content
Welcome back. In this lesson we build a lightweight stock news tracker that:
  • searches the web for the latest updates on a list of companies,
  • summarizes one interesting story for each company,
  • analyzes the sentiment of that summary (positive / neutral / negative),
  • exports the aggregated results into a clean Excel file for further review.
Create a new notebook (or script) and name it Stock News Pro. Save it and make sure your environment contains your OpenAI API key (for example, in a .env file).
Make sure your .env contains a valid API key (for example OPENAI_API_KEY=...). This lesson uses an agents package that provides an Agents SDK and a WebSearchTool to perform live web queries.

Overview

This guide is organized into four clear steps:
  1. Setup and imports
  2. Main logic (single async function that performs search, summarize, classify, and collect)
  3. Running the script (script vs. notebook)
  4. Output format and where files are saved
Follow the sections below to implement the tracker end-to-end.

1 — Setup and imports

Load environment variables and import the core libraries:
Then import the remaining dependencies:
Define the list of favorite stocks we want to track:

2 — Main logic

Below is a single consolidated async function that:
  1. Creates an Agent with the WebSearchTool.
  2. For each stock:
    • searches the web and requests one recent update in a single sentence,
    • extracts the summary,
    • asks the agent to classify sentiment (positive / neutral / negative),
    • maps the sentiment to an emoji,
    • extracts a source link if available,
    • appends the result to the results list.
  3. Converts the list to a pandas DataFrame and exports it to Excel (both the current working directory and the user’s Downloads folder when possible).
The script performs live web searches using the WebSearchTool. Expect variability in outputs and occasional missing source links. Monitor API usage and rate limits for your API key to avoid unexpected charges.

3 — Running the script

If you are running this as a standalone script, start the async function like this:
If you are in a Jupyter notebook, run the coroutine directly with:

4 — What the output looks like

When the script finishes you will see the Excel files (if both saves succeeded): Each Excel file contains the following columns: This output is ready for sorting, filtering, or importing into other analytics tools. That’s it — you now have a working stock news tracker that searches headlines, summarizes one recent update per company, classifies sentiment, and exports the results to Excel for later analysis. Hope you enjoyed this lesson.

Watch Video

Practice Lab