-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathStockTicker.gs
42 lines (34 loc) · 1.23 KB
/
StockTicker.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var botId = "your bot id here";
function sendText(text){
UrlFetchApp.fetch("https://api.groupme.com/v3/bots/post", {"method":"post", "payload":'{"bot_id":"' + botId + '","text":"' + text + '"}'});
}
function doPost(e){
var post = JSON.parse(e.postData.getDataAsString());
var text = post.text;
var name = post.name
if(text.toLowerCase().substring(0, 7) == "!stock "){
var tick = text.replace("!stock ", "");
if (tick == "")
sendText("Error: No tick was given");
sendText(stock(tick));
}else if (text.toLowerCase() == "!stock") {
sendText("Error: No tick was given");
}
}
function stock(query) {
// Replace 'demo' with your api key from http://www.alphavantage.co/support/#api-key
var url = 'http://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=' + query + '&apikey=demo'
try {
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
var price = data["Realtime Global Securities Quote"]["03. Latest Price"];
var name = data["Realtime Global Securities Quote"]["01. Symbol"];
}
catch (Exception)
{
Logger.log(Exception);
return ("Error occured");
}
return(name + "'s last price: " + price);
}