【问题标题】:GoogleSheet Cell Value TriggerGoogle 表格单元格值触发器
【发布时间】:2021-11-14 22:05:10
【问题描述】:
谁能告诉我如何创建脚本以在单元格值 (SP) 与目标值 (target sp) 相遇时触发电子邮件通知?
SP列公式如下:
function ASXLASTPRICE(asx_stock) {
var tickervar = asx_stock.substring(asx_stock.indexOf(":") + 1);
var url = "https://www.asx.com.au/asx/1/share/" + tickervar;
var response = UrlFetchApp.fetch(url);
var content = response.getContentText();
Logger.log(content);
var json = JSON.parse(content);
var last_price = json["last_price"];
return last_price;
}
数据样本:
【问题讨论】:
标签:
google-apps-script
google-sheets
【解决方案1】:
使用基于时间的触发器在最后价格变大时发送电子邮件
您可以使用触发器事件对象来控制触发器何时运行,以便您在证券交易所关闭时不运行。
function asxLastPrice(e) {
if (e['day-of-week'] < 6 && e.hour > 8 && e.hour < 3) {
let lp = PropertiesService.getScriptProperties().getProperty('lastprice');
var tickervar = asx_stock.substring(asx_stock.indexOf(":") + 1);
var url = "https://www.asx.com.au/asx/1/share/" + tickervar;
var response = UrlFetchApp.fetch(url);
var content = response.getContentText();
var json = JSON.parse(content);
var last_price = json["last_price"];
if (last_price > lp) {
PropertiesService.getScriptProperties().setProperty('lastprice', last_price);
GmailApp.sendEmail('recipient', 'subject', 'message');
}
return last_price;
}
}
function createtrigger() {
if(ScriptApp.getProjectTriggers().filter(t => t.getHandlerFunction() == "ASXLASTPRICE").length == 0) {
ScriptApp.newTrigger('ASXLASTPRICE').timeBased().everyMinutes(5).create();
}
}