Last active
August 29, 2015 14:16
-
-
Save LuckOfWise/f31040f93dd8e90e4234 to your computer and use it in GitHub Desktop.
1時間毎に予定をremottyに投稿するGAS
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 myFunction() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var calendar = CalendarApp.getDefaultCalendar(); | |
var from = new Date(); | |
// 今から60分後にかぶる予定をさがす | |
var to = new Date(from.getTime() + (1000 * 60 * 60)); | |
// このURLを自分のものに直してね | |
var link = "https://www.remotty.net/rooms/1/bot/message.json?(twitter用の奴と同じクエリ)"; | |
var events = calendar.getEvents( from , to ); | |
if (events.length > 0){ | |
var index = 1; | |
for (var i in events){ | |
var evt = events[i]; | |
var startTime = evt.getStartTime(); | |
var endTime = evt.getEndTime(); | |
// 開始時間が今から60分後の間の場合のみremottyに通知 | |
if (startTime >= from && startTime <= to) { | |
message = '【予定】' + formatTime(startTime.getHours()) + ":" + formatTime(startTime.getMinutes()) + '-' + formatTime(endTime.getHours()) + ":" + formatTime(endTime.getMinutes()) + " " + evt.getTitle() + '\n'; | |
sheet.getRange(index, 1).setValue(message); // 確認用にsheetにペタっと。 | |
UrlFetchApp.fetch(link, { | |
method: 'post', | |
payload: 'message=' + encodeURIComponent(message) | |
}); | |
} | |
} | |
} | |
} | |
function formatTime(value){ | |
return ("0"+value).slice(-2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment