Replicating the related rics column in the news view using python

Xim_O
Xim_O Newcomer

I'm looking to get the data from the related rics column as seen in the news monitor through python.

I can download news articles similar to the news monitor however this is missing the related rics column. I am using this code,

response = news.headlines.Definition("7974.T", count=150).get_data()

how would I add the column to the downloaded data

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Xim_O

    Thank you for reaching out to us.

    You can get RICs from the response.data.raw. A RIC is in the _qcode property with the "R:" prefix.

    image.png
  • Jirapongse
    Jirapongse ✭✭✭✭✭

    The code could be like this:

    import pandas as pd
    
    response = news.headlines.Definition("7974.T", count=150).get_data()
    
    data_array = []
    
    for story in response.data.raw[0]['data']:
        rics = []
        for code in story['newsItem']['contentMeta']['subject']:
            if code['_qcode'].startswith('R:'):
                rics.append(code['_qcode'].split(':')[1])
        data_array.append(
            {
                'StoryId': story['storyId'],
                'Headline': story['newsItem']['itemMeta']['title'][0]['$'],
                'FirstCreated': story['newsItem']['itemMeta']['firstCreated']['$'],
                'VersionCreated':story['newsItem']['itemMeta']['versionCreated']['$'],
                'RIC': ' '.join(rics),
                'SourceCode': story['newsItem']['contentMeta']['creator'][0]['_qcode']
            })
    df = pd.DataFrame(data_array)
    df
    
    
    image.png
  • Xim_O
    Xim_O Newcomer
    edited August 27

    Thanks, that's super clear.

    Is there any documentation about what each of the different letters mean in the raw data i.e. r for ric, m for ?

    That is the is there any documentation for interpreting what the individual _qcode means?

  • Hi @Xim_O ,

    For the meaning of each qcode, you can use News Monitor 2.0 application in LSEG Workspace. To access the app, simply type NEWS2.0 in the Workspace search bar.

    Then in the search bar of News Monitor, you can put the qcode there and then press enter button, the meaning of the qcode input will be shown.

    image.png

    You can also check article Exploring News Metadata - with Refinitiv Data Platform and Python 

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Xim_O

    There are news codes that can be used in news queries. You can refer to this document.

    Otherwise, please contact the helpdesk team directly via LSEG support for their meanings. Please include the URL of this discussion in your raised question to prevent it from being redirected back to this Q&A forum.