Tag: api-news

A News Reading and Sentiment Analysis App

We previously discussed how you can pull news items for specific topics/stocks using the StockViz News API. But all that the script did was show you a link to the news item. But who has the patience to click on a link, go to the website only to get annoyed by the ads? Wouldn’t it be nice if you could just read the news then and there?

Goose

Python Goose is an open-source article extractor written in python. It takes any news article and extracts the main body of the article and also all meta data. By adding a few lines of code, you can convert the previous script into a news reader of sorts that displays just the article, minus the cruft.

4 lines of code:

import the library: from goose import Goose
initialize goose: g = Goose()
extract the article: article = g.extract(url=r[‘SOURCE’])
clean the article: cleaned = article.cleaned_text.encode(‘ascii’, ‘ignore’)

You can see the whole script here.

Sentiment

One of the advantages of Mashape is that there are number of other APIs that you can access from within your account. Most of these have a “freemium” plan, just like our API. One of these is the Free Natural Language Processing Service.

The NLP Service takes a URL and returns the sentiment (positive, negative, neutral) along with a sentiment score.

2 lines of code:

make the call: response2 = unirest.get(…)
read the sentiment: sentiment = response2.body[“sentiment-text”]

You can see the whole script here.

Now you can tailor the what, when and how of the news you want to track. You could bundle all this up with a fancy user interface. Or pipe this through a messaging API (like SendHub?) Chief ingredient: your imagination!

Previously

API Samples on GitHub

We will be posting sample code on how to use the StockViz API on our repository at GitHub. All samples use Python and the readme walks you through how you need to be setup on windows to use the samples.

Basic News Reader

As a first cut, we put together a very basic news reader that uses the StockViz API to download company and topic specific news items. It prints out the title and the source url for now. You can jump directly to the python code here.

Next: Your Own News Reading and Sentiment Analysis App

Related