谷歌脚本每分钟触发不起作用

时间:2016-01-25 19:15:04

标签: javascript google-apps-script

我有以下脚本

    function scraper() {
        var url = 'http://gpa.shet.com.aspx';
        var sss = SpreadsheetApp.getActiveSpreadsheet();
        //var ss = SpreadsheetApp.openById('1im78ip4Wcmb1xbfZs8Lqy3-LP1SU9rC8E5OfKbOjJDg');
        //var sss = SpreadsheetApp.setActiveSpreadsheet(ss);
        var sheet = sss.getSheetByName("Sheet1");
        var rows = sheet.getDataRange();
        var numRows = rows.getNumRows();
        var response = UrlFetchApp.fetch(url);
        var contentText = response.getContentText();
        var pr = sheet.getRange('A1:Z1000');
        var cstring = contentText.tostring;
        var ui = SpreadsheetApp.getUi();
        var NHL = "New Agent";
        var nlength = contentText.length;
        // ui.alert(nlength);
        //ui.alert(contentText);
        //var g = 5;
        var clength = 200000;
        ///
        var temp = contentText;
        var count = (temp.match(/New Hot Lead/g) || []).length;
        var C6 = sheet.getRange('C6');
        var C8 = sheet.getRange('C8');
        var C10 = sheet.getRange('C10').getValue();
        var C10r = sheet.getRange('C10');

        if (count > 0) {
            var d = new Date();
            var hrs = d.getHours();
            var mins = d.getMinutes();
            var time1 = hrs + ":" + mins;

            if (C6.isBlank() == true) {
                C6.setValue(time1);
            } else if (C6.isBlank() == false) {
                C8.setValue(time1);
            }
        }

        if (count == 0) {
            C6.clear();
            C8.clear();
        }

        var time2 = 0.00347222222222222;

        if (C10 >= time2) {
            var D10 = sheet.getRange("D10");
            var alert = "NHLs for more than 5 minutes!";
            D10.setValue(alert);
            D10.setFontColor('Red');
        }
    }

现在,问题不在于代码本身,因为当我手动运行它时,它确实按照预期的方式工作。我的问题是时间驱动的触发器。我试图每分钟手动设置它,并在函数的末尾和外部添加triggerbuilder代码,但它仍然无法工作。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

尝试使用睡眠功能60秒。

sleep(60000);