Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
3 0 0 2

get_news_headline and quotation marks

hi there!

im trying to use the get_news_headlines function to pull out headlines for a list of entities.
The list if entities are saved on to a txt. file saved locally on my computer.

As an example, my txt file contains the name "SINGAPORE AEROSPACE MANUFACTURING PTE LTD". While running the get_news_headlines function, I pulled results for DAZN Pte Ltd. this occurs for other names as well. Please see search term on the right, along w the corresponding hits on the left.

1721721430404.png
Upon further investigation, my guess is that the search was not an exact search and hence threw out these items which I am not trying to get. Here is a screenshot of my search when manually performing the search via the News Monitor function on the app instead:
1721721519368.pngMy guess is that my code searches for the term and they are often automatically replaced by other keywords in eikon (i.e., if I do not include " " into my search then it is replaced by Singapore AND Aerospace AND MFLZ etc.).
I tried changing my code to update the search terms with " " to make it an exact match but it seems to generate a 503 error whenever the " " is added. My guess is that these quotation marks do not work well with the get_news_headlines function.

any work around this? some snippets of my code as well:

import eikon as ek
import pandas as pd
from datetime import datetime, timedel

# Function to read search terms from a text file
def read_search_terms(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        return [line.strip() for line in file if line.strip()]

# Function to get news headlines using Eikon Data API
def get_news_headlines(query, date_from, date_to, count=5):
    headlines = ek.get_news_headlines(query=query, count=count, date_from=date_from, date_to=date_to)
    return headlines


any help is appreciated!

eikon-data-api#productnewsnews-filternews-text-analyticsnews-topic-code-list
1721721430404.png (29.6 KiB)
1721721519368.png (147.9 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
84.6k 287 53 77

@Ruff

Thank you for reaching out to us.

You need to use the escape sequences for the double quotes.

ek.get_news_headlines(query="\\\"SINGAPORE AEROSPACE MANUFACTURING PTE LTD\\\"")

The output is:

1721810842122.png

You can also use the RD Library for Python.

headlines = rd.news.get_headlines('"SINGAPORE AEROSPACE MANUFACTURING PTE LTD"',count=100)
headlines

1721810951959.png

The RD examples are on GitHub.


1721810842122.png (18.8 KiB)
1721810951959.png (18.2 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 0 0 2

in contrast, this is my expected output
1721722080387.png


1721722080387.png (94.4 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.