Energy Research: Top News Energy

Getting Top News Energy Headlines and stories using Eikon Data API (Python)

This article demonstrate how to retrieve Top News Energy headlines and stories using Python code with Eikon Data API

What is Top News Energy?

Top News Energy presents the biggest energy stories that are moving markets and making headlines worldwide in an easy-to-use format. The content is updated 24/7 by dedicated and experienced global and local editors.

To access Top News energy, type "TOP/O" in the Refinitiv Eikon/Workspace Search box

In the News app, Top News Energy is published under the headline: *TOP NEWS* Energy, after clicking on this headline, the Top News Energy headlines app is shown.

Below is an example Full Story of the first Top News Energy headline, which can also be retrieved using Eikon Data API, as demonstrated in the next step

Prerequisite

You may contact your Refinitiv’s representative to help you to access the product

  • Eikon Data API
    • Eikon Desktop or Refinitiv workspace is running on your machine when running the notebook application
    • For how to start using Eikon Data API, you can follow its Quickstart guide
  • Required Python libraries and their version:
    • Python version 3.9.6 is being used here
    • eikon == 1.1.14
    • bs4 == 0.0.1
    • IPython == 7.27.0
  • Jupyter Lab or Jupyter Notebook application is installed and ready to use
    • You could use Eikon Codebook as well
      • The CodeBook is a cloud-hosted coding environment that lives inside Eikon/Workspace that can be used to develop Python notebook, script without any installation required because it's Python ready with common Python packages preinstalled and access to Refinitiv Data Platform Library
        Hence, CodeBook is Available in Refinitiv Workspace and Eikon, it also gives you access to our APIs and platform services in a single interface so you can be even more efficient. With our data, you can build analytics, applications, and other use cases that are critical for your daily workflow needs.
      • The list of available libraries installed in Refinitiv Codebook, including Refinitiv Data Platform (RDP) and many other useful libraries, can be found in Libraries&Extensions.md file.

Let's get started!

Step 1) import the necessary Python libraries and set the Eikon's App Key

The guide for the App Key creation can be found here

Step 2) Get News headline of TOP NEWS Energy

Get News headline for "TOP/O", a headline *TOP NEWS* Energy is included in the output dataframe (Please note that *TOP NEWS* Energy story will be updated over time.)

Step 3) Retrieve a content of Top News Energy

Get storyId of *TOP NEWS* Energy and use the storyId to get story body using get_news_story()

Story ID is urn:newsml:reuters.com:20171030:nTOPO:92, use this to retrieve the Top News Energy story.

From this story, we're going to retrieve Top News story IDs and headlines

  1. Headlines are in 'pre' tag
  2. Story IDs is in 'a' HTML tag with data-type = "storyId" (under data-story-id)

HTML function of IPython.display can be used to display it. You could see that these are the same News with the News app in screenshot at the beginning of this article

Use BeautifulSoup library as HTML parsing text to get headlines and Story Ids

3.1 ) Get headlines using the code below

3.2) Get Top News stories

3.2.1 ) Get story Ids using the code below

3.2.2) Use story IDs to retrieve news story

To retrieve latest news story

An example code to retrieve all news story in the list

Observation

Eikon Data API can be used to retrieve News headlines and stories, including the list of News in Top News Energy as demonstrated in this article.

The full code can be found in this GitHub Repository