Last active
February 15, 2021 03:24
-
-
Save moomdate/f37dd78aee00c362034a792fe9043645 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doGet(e) { | |
doRequest(); | |
} | |
function createTrigger(){ | |
deleteAllTrigger() | |
ScriptApp.newTrigger("doRequest") | |
.timeBased() | |
.everyMinutes(5) | |
.create() | |
} | |
function doRequest(){ | |
var response = UrlFetchApp.fetch("https://api.bitkub.com/api/market/ticker"); | |
var body = JSON.parse(response); | |
const {last} = body.THB_XRP; | |
if(last > 11){ | |
sendLineNotify(last); | |
Logger.log(`push notification XRP: ${last}`); | |
} | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
sheet.getRange(3,2).setValue([last]); | |
} | |
function sendLineNotify(value) { | |
var messages = { | |
"message": `ราคา XRP น้อยกว่า 11, ราคาปัจจุบัน ${value}` | |
}; | |
var url = "https://notify-api.line.me/api/notify"; | |
var token = ""; | |
var options = { | |
"method": "post", | |
"payload": messages, | |
"headers": { | |
"Authorization": "Bearer " + token | |
} | |
}; | |
UrlFetchApp.fetch(url, options); | |
} | |
function getCellValue(){ | |
var sheet = SpreadsheetApp.getActive().getSheetByName("settings"); | |
var setting1 = sheet.getRange(1, 2).getValue(); | |
Logger.log(setting1) | |
} | |
function deleteAllTrigger() { | |
var triggers = ScriptApp.getProjectTriggers(); | |
for (var i = 0; i < triggers.length; i++) { | |
ScriptApp.deleteTrigger(triggers[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment