{"id":1921641,"date":"2014-02-18T18:08:41","date_gmt":"2014-02-18T12:38:41","guid":{"rendered":"http:\/\/stockviz.biz\/index.php\/?p=1921641"},"modified":"2014-02-18T18:40:20","modified_gmt":"2014-02-18T13:10:20","slug":"news-reading-sentiment-analysis-app","status":"publish","type":"post","link":"https:\/\/stockviz.biz\/index.php\/2014\/02\/18\/news-reading-sentiment-analysis-app\/","title":{"rendered":"A News Reading and Sentiment Analysis App"},"content":{"rendered":"<p>We <a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/18\/api-samples-github\/\" title=\"a basic news reader\" target=\"_blank\">previously discussed<\/a> how you can pull news items for specific topics\/stocks using the <a href=\"https:\/\/www.mashape.com\/drona\/stockviz#!endpoint-News\" title=\"news api on mashape\" target=\"_blank\">StockViz News API<\/a>. 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&#8217;t it be nice if you could just read the news then and there?<\/p>\n<h3>Goose<\/h3>\n<p><a href=\"https:\/\/github.com\/grangier\/python-goose\" target=\"_blank\">Python Goose<\/a> 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 <a href=\"https:\/\/github.com\/shyams80\/StockViz\/blob\/master\/news\/01-simple\/news.py\" title=\"stock specific news using StockViz API\" target=\"_blank\">previous script<\/a> into a news reader of sorts that displays just the article, minus the cruft.<\/p>\n<p><strong>4 lines of code:<\/strong><\/p>\n<div class=\"row-fluid\">\n<div class=\"span10\">\n<table class=\"table table-bordered table-condensed\">\n<tbody>\n<tr>\n<td><small>import the library:<\/small><\/td>\n<td><small>from goose import Goose<\/small><\/td>\n<\/tr>\n<tr>\n<td><small>initialize goose:<\/small><\/td>\n<td><small>g = Goose()<\/small><\/td>\n<\/tr>\n<tr>\n<td><small>extract the article:<\/small><\/td>\n<td><small>article = g.extract(url=r[&#8216;SOURCE&#8217;])<\/small><\/td>\n<\/tr>\n<tr>\n<td><small>clean the article:<\/small><\/td>\n<td><small>cleaned = article.cleaned_text.encode(&#8216;ascii&#8217;, &#8216;ignore&#8217;)<\/small><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>You can see the whole script <a href=\"https:\/\/github.com\/shyams80\/StockViz\/blob\/master\/news\/02-reader\/news-reader.py\" title=\"python news reader\" target=\"_blank\">here<\/a>.<\/p>\n<h3>Sentiment<\/h3>\n<p>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 &#8220;freemium&#8221; plan, just like our API. One of these is the <a href=\"https:\/\/www.mashape.com\/loudelement\/free-natural-language-processing-service#!documentation\" target=\"_blank\">Free Natural Language Processing Service<\/a>. <\/p>\n<p>The NLP Service takes a URL and returns the sentiment (positive, negative, neutral) along with a sentiment score.<\/p>\n<p><strong>2 lines of code:<\/strong><\/p>\n<div class=\"row-fluid\">\n<div class=\"span10\">\n<table class=\"table table-bordered table-condensed\">\n<tbody>\n<tr>\n<td><small>make the call:<\/small><\/td>\n<td><small>response2 = unirest.get(&#8230;)<\/small><\/td>\n<\/tr>\n<tr>\n<td><small>read the sentiment:<\/small><\/td>\n<td><small>sentiment = response2.body[&#8220;sentiment-text&#8221;]<\/small><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>You can see the whole script <a href=\"https:\/\/github.com\/shyams80\/StockViz\/blob\/master\/news\/02-reader\/news-reader-sentiment.py\" target=\"_blank\">here<\/a>.<\/p>\n<p>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 <a href=\"https:\/\/www.mashape.com\/sendhub\/sendhub#!documentation\" target=\"_blank\">SendHub<\/a>?) Chief ingredient: your imagination!<\/p>\n<h6>Previously<\/h6>\n<ul>\n<li><a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/17\/stockviz-api\/\" target=\"_blank\">The StockViz API<\/a><\/li>\n<li><a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/17\/linking-mashape-stockviz-accounts\/\" target=\"_blank\">Linking Your Mashape and StockViz Accounts<\/a><\/li>\n<li><a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/18\/api-samples-github\/\" title=\"API Samples on GitHub\" target=\"_blank\">API Samples on GitHub<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t it &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3131,9],"tags":[3151],"class_list":["post-1921641","post","type-post","status-publish","format-standard","hentry","category-api","category-your-money","tag-api-news","entry"],"_links":{"self":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/1921641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/comments?post=1921641"}],"version-history":[{"count":0,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/1921641\/revisions"}],"wp:attachment":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/media?parent=1921641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/categories?post=1921641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/tags?post=1921641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}