Extract News Title and Story for the past year (E.g. AAPL.O/ 005930.KS)

Hi Team, noted there is some example under codebook for News and News Metadata.


What if I want to extract the past one year record for all the news related to a stock including both title and story.


May I know how can I conduct the api code? You may use AAPL.O or 005930.KS as an example.



Answers

  • @Edwin Kwan There is an example in Codebook __Examples__/10. News but here is the skinny:

    import refinitiv.data as rd
    from refinitiv.data.content import news
    from IPython.display import HTML
    import pandas as pd
    import numpy as np
    from datetime import datetime,timedelta
    import time
    import warnings
    warnings.filterwarnings("ignore")
    rd.open_session()
    dNow = datetime.now().date()
    maxenddate = dNow - timedelta(days=365) #upto months=15
    compNews = pd.DataFrame()
    riclist = ['AAPL.O','005930.KS'] # 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", 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

    1730199510833.png

    Further in the example you can get more metadata such as new topic codes etc. I hope this can help.