question

Upvotes
Accepted
7 1 1 6

Get_news - count of news articles for a RIC, date range and topic

Hi,

As above title please, looking to run a count of news articles for a particular RIC, date range and ‘topic’. I.e. TSLA.O, 6th November 2023 - 10 November 2023, topic=SIGDEV.

I’d like a count of news articles per day.

Is this possible?

I’m aware of how to run get news story for the above, but it’s time consuming. I’d just like to run a count of news articles or headlines - that meet the above criteria - per each day within the specified date range.


Thank you

python#technologynews
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.

1 Answer

· Write an Answer
Upvotes
Accepted
5.8k 21 2 6

Hi @di.ti,


I believe it might be best to use the RD Lib. for Python's functionanity called 'Delivery' in the following way:

import refinitiv.data as rd
try:  # The following libraries are not available in Codebook, thus this try loop
    rd.open_session(
        config_name="C:\\Example.DataLibrary.Python-main\\Configuration\\refinitiv-data.config.json", # this is where my config file is located
        name="desktop.workspace") # rdp.platform
except:
    rd.open_session()

company = "TSLA.O"
start = "2023-11-06"
end = "2023-11-10"
source = "SIGDEV"

request_definition = rd.delivery.endpoint_request.Definition(
    url=f"https://api.refinitiv.com/data/news/v1/headlines?query={company}%20and%20{source}%20daterange:%22{start},{end}%22",
    method = rd.delivery.endpoint_request.RequestMethod.GET)
response = request_definition.get_data()
response.data.raw['meta']['count']

1699880332506.png


Does this meet your need?

N.B.: You can find info abou this endpoint (which is named a `url` above) here; e.g.: "Limit of headline (default 10, range value: [0, 100])"


1699880332506.png (60.7 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.

Hi @jonathan.legrand

Thank you for this. This works at generating a count of all articles in the date range, but any chance that it could generate a count of how many articles meet this criteria for each day within the start date and end date?

@di.ti , in that case, this should work:

company:str="TSLA.O"
  start: str ="2023-11-01"
  end: str ="2023-11-10"
  source: str ="SIGDEV"
  strt_dte:datetime=datetime.strptime(start,'%Y-%m-%d')
  strt_dtep1:datetime=datetime.strptime(start,'%Y-%m-%d') + timedelta(days=1)
  end_dte:datetime=datetime.strptime(end, '%Y-%m-%d')
  delta:timedelta=end_dte-strt_dte
  for i,j,k in zip(
  [(strt_dte+timedelta(days=i)).strftime('%Y-%m-%d') for i in range(delta.days+1)],
  [(strt_dtep1+timedelta(days=i)).strftime('%Y-%m-%d') for i in range(delta.days+1)],
  [i for i in range(delta.days+1)]):
  request_definition: rd.delivery._data._endpoint_definition.Definition=rd.delivery.endpoint_request.Definition(
  url=f"https://api.refinitiv.com/data/news/v1/headlines?query={company}+and+{source}+daterange:\{i},{j}\",
  method=rd.delivery.endpoint_request.RequestMethod.GET)
  response:rd.delivery._data._response.Response=request_definition.get_data()
  if k==0:
  req_def_lst:list[int]=[response.data.raw['meta']['count']]
  else:
  req_def_lst.append(response.data.raw['meta']['count'])
  print(f"{i}to{j}:{response.data.raw['meta']['count']} article(s)")
  print(req_def_lst)

1699897387004.png

Hi @jonathan.legrand, Works perfect! Thank you very much!

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.