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
1 0 0 1

How do i get the data for top news without specifying the RICs I want.

I'm hoping to obtain the top news data from Refinitiv through API/python. Im basing my code on the example provided in the Codebook under News. How do i get the data for top news without specifying the RICs want.


this is my current code:

rd.open_session()

dNow = datetime.now().date()

maxenddate = dNow - timedelta(days=7) #upto months=15

compNews = pd.DataFrame()

riclist = ['AAPL.O'] # can also use Peers, Customers, Suppliers, Monitor, Portfolio to build universe


for ric in riclist:

try:

cHeadlines = rd.news.get_headlines("R:" + ric + " AND Language:LEN AND Source:RTRS", start= str(dNow),

end = str(maxenddate), count = 10)

cHeadlines['cRIC'] = ric

if len(compNews):

compNews = pd.concat([compNews,cHeadlines])

else:

compNews = cHeadlines

except Exception:

pass


compNews


baseurl = "/data/news/v1/stories/"

fullcodelist = pd.DataFrame()

compNews['storyText'] = str()

compNews['q_codes'] = str()

compNews['pIDs_mentioned'] = str()

compNews['RICs_mentioned'] = str()

compNews['urgency'] = str()


for i, uri in enumerate(compNews['storyId']):

request_definition = rd.delivery.endpoint_request.Definition(

url = baseurl + uri,

method = rd.delivery.endpoint_request.RequestMethod.GET

)

response = request_definition.get_data()

time.sleep(0.1)

rawr = response.data.raw

if 'newsItem' in rawr.keys():

compNews['storyText'][i] = rawr['newsItem']['contentSet']['inlineData']['$']

topics = rawr['newsItem']['contentMeta']['subject']

rics = [x for x in rawr['newsItem']['assert'] if x['_qcode'].startswith("R:")]

compNews['q_codes'][i] = [d['_qcode'] for d in topics]

compNews['pIDs_mentioned'][i] = [x for x in compNews['q_codes'][i] if x.startswith("P:")]

compNews['RICs_mentioned'][i] = [d['_qcode'] for d in rics]

compNews['urgency'] = rawr['newsItem']['contentMeta']['urgency']['$'] # 1 = hot, 3 = regular


rd.close_session()

#productnews-topic-code-list
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.

@shivu.b

Hi,

Please be informed that a reply has been verified as correct in answering the question, and marked as such.

Thanks,

AHS

@shivu.b

Hi,

Please be informed that a reply has been verified as correct in answering the question, and marked as such.

Thanks,

AHS

1 Answer

· Write an Answer
Upvote
Accepted
15.3k 32 5 10

Hi @shivu.b,

Have you had a chance to check the answer in This thread as below

It could be top news

import refinitiv.data as rd
from refinitiv.data.content import news
 
rd.open_session()
    
top_news = news.top_news.hierarchy.Definition().get_data();
top_news.data.df

1702538859688.png

Then, use the topNewsId to get news in the sub-category.

front_page = news.top_news.Definition(top_news.data.df["topNewsId"][0]).get_data()
front_page.data.df

1702538917151.png


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.