Getting data frame directly from using news API
In Eikon, news code [HNXB] contains headlines with links to download the file. Is there a way for us to download the data frame directly via Codebook? I'm only able to get the headlines but couldn't find a code that would extract the data directly.
ek.get_news_headlines(query = 'HNXB', count=10)
Best Answer
-
Step 1: get headline
Step 2: get story id
I can only add 2 pictures in an answer, so please see further comment on this answer for more detail.
0
Answers
-
Step 3: get Side by Side API token with Eikon Desktop
Step 4: prepare Side by Side API command
Step 5: open the URL using the prepared command
url = 'http://127.0.0.1:9000/sxs/v1';
headers = {
'Content-Type': 'application/json',
}
response = requests.request('POST', url, data=commandString, headers=headers)
print(response.text)0 -
@chrisma.salut So im thinking that you are looking to retrieve the news stories - so get_news headlines returns a dataframe of max 100 items per API call corresponding to a query you give it - in your case 'HNXB'.
df = ek.get_news_headlines(query = 'HNXB', count=10)
dfSo this returns a dataframe of 10 headline items and you need to pass the storyId to a second API called get_news_story - which will return you the html formatted story text. The folllowing routine stores the formatted html news story in a new column called storytext.
df['storytext'] = ''
for i, uri in enumerate(df['storyId']):
df['storytext'][i] = ek.get_news_story(uri)
dfYou can display the story using:
from IPython.display import HTML
HTML(df['storytext'][0])I have noticed in your query the news story text is actually a download link - if you changed the query to say VOD.L and repeated the exercise - it would display a news item. It is working correctly. I hope this can help.
0 -
Hello Chavalit,
Thank you for your assistance on this query. Client can't get past step 3 as they are getting an error. Any idea what's causing this?
0 -
Hi all, I dont verified your answers because it doenst match the requirement : downloading the file not the news. I found out my own way without applying any side to side api :
###1. get the table news
###2. get the story id
###2. get the file (downloaded in download folder)
df1Id=df1[df1['date']== a]['storyId'][0]
df1_url=ek.get_news_story(df1Id)
link1 = re.search('href="(.*)" data-type', df1_url)
webbrowser.open(link1.group(1))
0 -
@khangdiep Sorry we did not hit the mark this time. Thanks for taking the trouble to post your solution here - i'm sure others in the community will benefit from this addition. I have verified that this does indeed open the link in the webbrowser - however it does not download the file. From here you could try to scrape the rendered HTML I suppose. Once again thanks so much for contributing your solution.0
-
the file is downloaded in "download" folder as the default location from website download. the download window is popped up and ask to choose the save folder location - but u can skip this step as keep running the code to download the other news file til the code end.0
Categories
- All Categories
- 6 AHS
- 39 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 中文论坛