Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Google Apps Scriptで三日坊主を克服する

tadaken3
October 30, 2017

Google Apps Scriptで三日坊主を克服する

10/31にGaiaxさんが主催の『Google Apps Script 活用ミートアップ』で使用した資料です。
https://gaiax.connpass.com/event/69200/

tadaken3

October 30, 2017
Tweet

More Decks by tadaken3

Other Decks in Programming

Transcript

  1. Google Apps ScriptͰࡾ೔๥ओΛࠀ෰͢Δ //IFTTTͷ೔෇ܗ͔ࣜΒ௨ৗͷ೔෇ʹม׵ function toDateFromIFTTT(str){ str = String(str); str

    = str.replace(/at.*/,"")//ਖ਼نදݱͰatΑΓޙΖͷ෦෼Λ࡟আ d = new Date(str); return d; } IFTTTͷ೔෇ܗࣜ(str)Λdateʹม׵
  2. Google Apps ScriptͰࡾ೔๥ओΛࠀ෰͢Δ var ss = SpreadsheetApp.getActiveSpreadsheet(); //εϓϨουγʔτΛऔಘ var sheet

    = ss.getSheetByName("log"); //γʔτΛऔಘ //γʔτͷ࠷ऴߦʹܦա೔Λܭࢉ͢ΔࣜΛηοτ͢Δ function setFormuraLastRow(){ //γʔτͷ࢖༻ൣғͷ͏ͪ࠷ऴߦΛऔಘ var maxRow = sheet.getDataRange().getLastRow(); //Aྻͷ࠷ऴߦͷ஋Λऔಘ var str = sheet.getRange(maxRow,1).getValue(); //εϓϨουγʔτ༻ͷࣜ var code = '=TODAY() - TO_DATE(B'+ maxRow+')'; //ϑΥʔϚοτͨ͠೔෇Ληοτ sheet.getRange(maxRow,2).setValue(toDateFromIFTTT(str)); //ࣜΛηοτ͢Δ sheet.getRange(maxRow,3).setFormula(code); } ܦա೔਺Λܭࢉ͢Δ
  3. Google Apps ScriptͰࡾ೔๥ओΛࠀ෰͢Δ //LINEʹ௨஌ΛૹΔؔ਺ function sentToLine(message){ var token = "ઌఔऔಘͨ͠ΞΫηετʔΫϯ";

    var options = { "method" : "post", "payload" : "message=" + message, "headers" : {"Authorization" : "Bearer "+ token} }; UrlFetchApp.fetch("https://notify-api.line.me/api/notify",options); } LINE NotifyʹϝοηʔδΛૹΔ
  4. Google Apps ScriptͰࡾ೔๥ओΛࠀ෰͢Δ function main(){ setFormuraLastRow() var maxRow = sheet.getDataRange().getLastRow();

    var passDate = sheet.getRange(maxRow,3).getValue(); var message =""; //ܦա೔͕̏೔΋͘͠͸7೔Ҏ্ͩͬͨΒLINEʹ௨஌ΛૹΔ if (passDate==3 || passDate>=7){ message = "࠷ऴτϨʔχϯά͔Β"+ passDate + "೔ܦա͠·ͨ͠"; sentToLine(message); } } ૊Θ࣮ͤͯ૷͢Δ