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.ramchandani
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.ramchandani 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
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
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛