Last active
February 27, 2016 01:49
-
-
Save yukihirai0505/be0716571902d23c2600 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
var bk = SpreadsheetApp.getActiveSpreadsheet(); | |
var weeklySh = bk.getSheetByName("[シート名]"); | |
/** | |
先週分のanalyticsのデータをセットする | |
**/ | |
function setLastWeekData() { | |
// 毎週月曜日に実行されるので7日前が月曜日で1日前は日曜日 | |
var today = new Date(); | |
// 実行日が月曜日のとき | |
if (today.getDay() === 1) { | |
var lastMonday = getLastNdays(7); | |
var lastSunday = getLastNdays(1); | |
var weeklyColumn = getWeeklyColumnFromRow1(lastMonday, lastSunday); | |
setTotalPVAndUU(weeklySh, lastMonday, lastSunday, weeklyColumn.getColumn()); | |
setUUFromPath(weeklySh, lastMonday, lastSunday, weeklyColumn.getColumn(), '\?mag-from'); | |
setUUFromPath(weeklySh, lastMonday, lastSunday, weeklyColumn.getColumn(), '\?app-from=push'); | |
} else { | |
Logger.log("月曜日に実行して下さい"); | |
} | |
} | |
/** | |
row1から先週の日付が入力されているカラムを返す | |
@return 先週の日付が入っているカラム | |
**/ | |
function getWeeklyColumnFromRow1(lastMonday, lastSunday) { | |
var row = 1; | |
var lastColumn = weeklySh.getLastColumn(); | |
var targetColumn; | |
var searchString = lastMonday.replace(/-/g , "\/") + "~" + lastSunday.replace(/-/g , "\/"); | |
for(var i = 1; i < lastColumn; i++){ | |
var target = weeklySh.getRange(row, i); | |
if(target.getValue() === searchString) { | |
targetColumn = weeklySh.getRange(row, i); | |
break; | |
} | |
// 無ければセット | |
if(target.getValue() === "") { | |
targetColumn = weeklySh.getRange(row, i); | |
targetColumn.setValue(searchString); | |
break; | |
} | |
} | |
return targetColumn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment