how can we get news directly on codebook?

how can we get news directly on codebook? can it be done without the api key
i am using currently
df = ek.get_news_headlines('Topic:COVID AND Language:LEN AND Source:RTRS', date_from='2021-04-01T09:00:00',date_to='2021-04-02T09:00:00',count=50)
df.head()
is it possible to do it directly on codebook? if so function?
Best Answer
-
@akshmita so Codebook uses a default app key - you obviously have to be logged into Eikon in order to launch codebook.
import refinitiv.dataplatform.eikon as ek
from IPython.display import HTML
ek.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')then use your API call:
df = ek.get_news_headlines('Topic:COVID AND Language:LEN AND Source:RTRS', date_from='2021-04-01T09:00:00',date_to='2021-04-02T09:00:00',count=50)
df.head()and as expected it works fine:
0
Answers
-
thanks @jason.ramchandani01
I have another issue: eikon news through api should be available for last 15 months,
however i am getting from june 2020 (last 12 months)
any way to sort the issue?
0 -
@akshmita So the limit of news headlines per API call is 100 (in your case you limit it at 50) - to get more headlines than this you will have to iterate using date as a parameter. Please check the generalised example below:
import pandas as pd
import datetime
from datetime import datetime
import dateutil.relativedelta
now = datetime.now()
maxenddate = now - dateutil.relativedelta.relativedelta(months=15) #months,days
print(now, maxenddate)newsdf = pd.DataFrame()
startdf=now
while startdf >= maxenddate:
try:
df1 = ek.get_news_headlines('Topic:COVID AND Language:LEN AND Source:RTRS', date_to = startdf, count=100)
startdf = df1['versionCreated'].min().replace(second=0,microsecond=0,tzinfo=None).strftime('%Y/%m/%d %H:%M')
startdf = datetime.strptime(startdf,'%Y/%m/%d %H:%M')
if len(newsdf):
newsdf = pd.concat([newsdf, df1], axis=0)
else:
newsdf = df1
except Exception:
break
newsdf.info()This will give you 15 months worth of news for a query (obviously you can just replace my query with whatever query you want). I trust this can help.
0 -
@jason.ramchandani01 thanks for the code,
i tried the code, but getting 0 results, may i doing something wrong?
import datetime
from datetime import datetime
import dateutil.relativedelta
now = datetime.now()
maxenddate = now - dateutil.relativedelta.relativedelta(months=15) #months,days
print(now, maxenddate)
output:
2021-09-23 11:03:46.402525 2020-06-23 11:03:46.402525
newsdf = pd.DataFrame()
startdf=now
while startdf >= maxenddate:
try:
df1 = ek.get_news_headlines('Topic:COVID AND Language:LEN AND Source:RTRS', date_to = startdf, count=100)
startdf = df1['versionCreated'].min().replace(second=0,microsecond=0,tzinfo=None).strftime('%Y/%m/%d %H:%M')
startdf = datetime.strptime(startdf,'%Y/%m/%d %H:%M')
if len(df1):
newsdf = pd.concat([newsdf, df1], axis=0)
else:
newsdf = df1
except Exception:
break
newsdf.info()
output:
<class 'pandas.core.frame.DataFrame'> Index: 0 entries Empty DataFrame
0 -
@akshmita apols I found 2 small errors in the code I pasted - one missing import and if len(df1): should be if len(newsdf): - I have altered the code above and it works fine. You might want to test it by not running the full 15 months of news - as this will take some time - maybe change the following line:
maxenddate = now - dateutil.relativedelta.relativedelta(months=15) #months,days
to
maxenddate = now - dateutil.relativedelta.relativedelta(days=3) #months,days
I hope this can help.
0
Categories
- All Categories
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 33 Data Model Discovery
- 682 Datastream
- 1.4K DSS
- 613 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 248 ETA
- 552 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.8K Refinitiv Data Platform
- 622 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 191 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 84 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛