From 1655e5d76c65556716e95eca2dab8a0a1f25dc51 Mon Sep 17 00:00:00 2001 From: MSPawanRanjith Date: Sat, 3 Mar 2018 21:31:40 +0530 Subject: [PATCH 1/6] Final Fix Removed Keys --- .clasp.json | 1 + Code.js | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ appsscript.json | 11 +++++ 3 files changed, 133 insertions(+) create mode 100644 .clasp.json create mode 100644 Code.js create mode 100644 appsscript.json diff --git a/.clasp.json b/.clasp.json new file mode 100644 index 0000000..0e8ede7 --- /dev/null +++ b/.clasp.json @@ -0,0 +1 @@ +{"scriptId":"1haPCAarlTD_wMzX1-_nk8lbz22A2FR4zcGypBQr6N50JvcGjEg0dFHD5"} diff --git a/Code.js b/Code.js new file mode 100644 index 0000000..e0f1619 --- /dev/null +++ b/Code.js @@ -0,0 +1,121 @@ +//Opening the sheets using Id +var sheetID = "Insert Your Sheet ID"; +var sheet = SpreadsheetApp.openById(sheetID).getSheetByName("Sheet1"); + +//Global Variables +var rowList=[]; + +//driver function +function main(){ + + var endColumn=sheet.getLastColumn()-1; + var startColumn=1; + var startRow=2; + Logger.log(endColumn); + var watchList=sheet.getRange(startColumn,startRow,startColumn,endColumn).getValues(); + //Logger.log(test); + //var watchList=sheet.getRange(''+startColumn+":"+endColumn).getValues(); + Logger.log(watchList); + + for(var i = 0; i < watchList.length; i++) { + var stockList = watchList[i]; + //Logger.log(stockList); + for(var j = 0; j < stockList.length; j++) { + //Logger.log(stockList[j]); + var res=getStockQuote(stockList[j]); + } + } + + rowList.unshift(res); + //Logger.log(rowList); + + //Append the price to the Sheet + sheet.appendRow(rowList); +} + +function getStockQuote(stock){ + var gTime; + var gName; + var mainUrl="https://api.iextrading.com/1.0/stock/"; + var book="/book"; + var url=mainUrl+stock+book; + Logger.log(url); + var results=fetch(url); + //Logger.log(results); + for each( var result in results) { + // Logger.log(result); + var name=result.companyName; + var value=result.high; + var time=result.openTime; + rowList.push(value); + //sheet.appendRow(rowList); + gTime=time; + gName=name.split(" "); + //Logger.log(gName[0]); + break; + } + + //Check For recent news and its sentiment + sentimentCheck(gName[0]); + + return gTime; + +} +function sentimentCheck(stockName){ + + //News API Call + var mainUrl="https://newsapi.org/v2/top-headlines?q="; + var remain="&languag=en&category=business&sortBy=publishedAt&apiKey="; + var url=mainUrl+stockName+remain; + + //Fetch the news + var results=fetch(url); + Logger.log(results); + + if(results.totalResults ==0){ + Logger.log("No recent News"); + } + else{ + var news=results.articles[0].title; + //Logger.log(name); + var sense=queryHostedModel(news); + if (sense==="positive"){ + MailApp.sendEmail("abc.com", "StockWatch","News : "+ news+"\nCheck this Stock : "+stockName+"\nTrend : Its increasing"); + } + if(sense==="negative"){ + MailApp.sendEmail("abc.com", "StockWatch","News : "+ news+"\nCheck this Stock : "+stockName+"\nTrend : decreasing"); + } + } + +} + +function fetch(url) { + var response = UrlFetchApp.fetch(url); //makes api calls + var parsed_response = JSON.parse(response); + return parsed_response; +} + + + +function queryHostedModel(news) { + // When querying hosted models you must always use this + // specific project number. + var projectNumber = '414649711441'; + var hostedModelName = 'sample.sentiment'; + + // Query the hosted model with a positive statement. + var predictionString = news; + var prediction = Prediction.Hostedmodels.predict( + { + input: { + csvInstance: [predictionString] + } + }, + projectNumber, + hostedModelName); + // Logs Sentiment: positive. + Logger.log('Sentiment: ' + prediction.outputLabel); + return prediction.outputLabel; + + +} \ No newline at end of file diff --git a/appsscript.json b/appsscript.json new file mode 100644 index 0000000..5a9322a --- /dev/null +++ b/appsscript.json @@ -0,0 +1,11 @@ +{ + "timeZone": "Asia/Calcutta", + "dependencies": { + "enabledAdvancedServices": [{ + "userSymbol": "Prediction", + "serviceId": "prediction", + "version": "v1.6" + }] + }, + "exceptionLogging": "STACKDRIVER" +} \ No newline at end of file From cfbc734929d04884e9cf39dde86e8485c6088435 Mon Sep 17 00:00:00 2001 From: MSPawanRanjith Date: Sat, 3 Mar 2018 21:43:04 +0530 Subject: [PATCH 2/6] Organised the files --- .clasp.json => StockWatch/.clasp.json | 0 Code.js => StockWatch/Code.js | 0 README.md => StockWatch/README.md | 0 appsscript.json => StockWatch/appsscript.json | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename .clasp.json => StockWatch/.clasp.json (100%) rename Code.js => StockWatch/Code.js (100%) rename README.md => StockWatch/README.md (100%) rename appsscript.json => StockWatch/appsscript.json (100%) diff --git a/.clasp.json b/StockWatch/.clasp.json similarity index 100% rename from .clasp.json rename to StockWatch/.clasp.json diff --git a/Code.js b/StockWatch/Code.js similarity index 100% rename from Code.js rename to StockWatch/Code.js diff --git a/README.md b/StockWatch/README.md similarity index 100% rename from README.md rename to StockWatch/README.md diff --git a/appsscript.json b/StockWatch/appsscript.json similarity index 100% rename from appsscript.json rename to StockWatch/appsscript.json From 4608fcf6cd42bdeb4deaa595c50204274a908375 Mon Sep 17 00:00:00 2001 From: MSPawanRanjith Date: Sat, 3 Mar 2018 21:45:11 +0530 Subject: [PATCH 3/6] Created Readme File --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a46c14 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# GoogleAppsScript \ No newline at end of file From 4d3e58c44ccc4eb8ccef8964ad88184d47e4c8d4 Mon Sep 17 00:00:00 2001 From: M S Pawan Ranjith Date: Sat, 3 Mar 2018 22:05:47 +0530 Subject: [PATCH 4/6] Updated Readme --- StockWatch/README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/StockWatch/README.md b/StockWatch/README.md index 8a46c14..2dc257d 100644 --- a/StockWatch/README.md +++ b/StockWatch/README.md @@ -1 +1,26 @@ -# GoogleAppsScript \ No newline at end of file +# Stack Watch +Its a container bound app-script, which takes the watch stock list from the google spreadsheet its linked to and it finds the recent business news related to the watch list Stock, and performs sentimental analysis using Prediction API, and alerts if the stock may increase or decrease and also along with it records their Market high values to the spreadsheet. + +### API's USED + + - News Api + - iexTrading + - Prediction API (GCP) + +### Sample Spreadsheet +![Example Spreadsheet ](https://image.ibb.co/fjCc7n/appscript.jpg) + - The Watch List Stock are entered in Row1 (To be entered by user) + - The timestamp is UNIX TimeStamp + - The values are in USD and its High Value +### Sample Mail +![Email Sample](https://image.ibb.co/eTLpnn/appscript2.jpg) + - News, the Stock and its predicted Trend will be mailed +### NOTE +Please replace the following: + - The sheetID in line 2 of code.gs + - The News API Key in line 68 of code.gs + - The e-Mail id in line 83 and 86 of code.gs + +If any issues found please be free to create an issue + +Follow me on [Github](github.com/mspawanranjith) From 0036cfce79784751ca3177782f8e190d5698ab3e Mon Sep 17 00:00:00 2001 From: M S Pawan Ranjith Date: Sat, 3 Mar 2018 22:07:26 +0530 Subject: [PATCH 5/6] Updated Stock Watch --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a46c14..6b7d9b6 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# GoogleAppsScript \ No newline at end of file +# GoogleAppsScript + +### 1 Stock Watch + +Its a container bound app-script, which takes the watch stock list from the google spreadsheet its linked to and it finds the recent business news related to the watch list Stock, and performs sentimental analysis using Prediction API, and alerts if the stock may increase or decrease and also along with it records their Market high values to the spreadsheet. From 2604ef94f99011f80178d5739275a064acac67b1 Mon Sep 17 00:00:00 2001 From: M S Pawan Ranjith Date: Sun, 4 Mar 2018 12:47:51 +0530 Subject: [PATCH 6/6] Github profile linked --- StockWatch/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StockWatch/README.md b/StockWatch/README.md index 2dc257d..88ab24e 100644 --- a/StockWatch/README.md +++ b/StockWatch/README.md @@ -23,4 +23,4 @@ Please replace the following: If any issues found please be free to create an issue -Follow me on [Github](github.com/mspawanranjith) +Follow me on [Github](https://github.com/mspawanranjith)