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()