Created
August 31, 2015 05:21
-
-
Save tinsep19/e0d75192a5d9018cd30d to your computer and use it in GitHub Desktop.
Google Spreadsheetに会議室ID一覧を記入して、対象の会議室の予定をメールで送るサンプル
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 main() { | |
var i, l, calendar_ids, summaries = [], | |
day = new Date(); | |
calendar_ids = load_calendar_ids(); | |
for (i = 0, l = calendar_ids.length; i < l; i++) { | |
summaries.push(summarize_of_day(calendar_ids[i], day)); | |
} | |
MailApp.sendEmail("who@example.com", subject_of_summary(day), summaries.join("\n\n")); | |
} | |
function subject_of_summary(day) { | |
return Utilities.formatDate(day, 'Asia/Tokyo', 'yyyy-MM-ddの予定'); | |
} | |
function summarize_of_day(calendar_id, day) { | |
var j, m, calendar, events, summary = []; | |
calendar = CalendarApp.getCalendarById(calendar_id); | |
events = calendar.getEventsForDay(day || new Date()); | |
summary.push(calendar.getName()); | |
if (events.length > 0) { | |
for (j = 0, m = events.length; j < m; j++) { | |
summary.push(summarize_of_event(events[j])); | |
} | |
} else { | |
summary.push('No events.'); | |
} | |
return summary.join("\n"); | |
} | |
function summarize_of_event(event) { | |
var st, et, title, creator; | |
title = event.getTitle(); | |
st = Utilities.formatDate(event.getStartTime(), 'Asia/Tokyo', 'HH:mm'); | |
et = Utilities.formatDate(event.getEndTime(), 'Asia/Tokyo', 'kk:mm'); | |
creator = event.getCreators().join(','); | |
return st + ' - ' + et + ' ' + title + ' [' + creator + ' ]'; | |
} | |
function load_calendar_ids() { | |
var file, sheet, calendars; | |
var i, l; | |
file = SpreadsheetApp.getActive(); | |
sheet = file.getActiveSheet(); | |
l = sheet.getLastRow(); | |
data = sheet.getSheetValues(1, 1, l, 1); | |
calendars = []; | |
for (i = 0; i < l; i++) { | |
calendars.push(data[i][0]); | |
} | |
return calendars; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment