Skip to content

Instantly share code, notes, and snippets.

@yoonchulkoh
Last active November 8, 2017 23:26
Show Gist options
  • Save yoonchulkoh/276305a41435bb546ec3 to your computer and use it in GitHub Desktop.
Save yoonchulkoh/276305a41435bb546ec3 to your computer and use it in GitHub Desktop.
DMM英会話スケジュール自動登録スクリプト
/*
* DMM英会話のスケジュールを登録する
*/
var CALENDAR_NAME = 'YOUR CALENDAR NAME';
var SEARCH_QUERY = 'is:unread subject:"【DMM英会話】レッスン予約完了のお知らせ"';
function registDMMEikaiwaCalendar() {
// 指定したカレンダーを取得
var calendars = CalendarApp.getCalendarsByName(CALENDAR_NAME);
var calendar;
if (calendars.length === 0) {
Logger.log(CALENDAR_NAME + "カレンダーが見つかりません");
return;
} else {
calendar = calendars[0];
}
var threads = GmailApp.search(SEARCH_QUERY, 0, 1);
if (threads.length === 0) {
Logger.log("メールが見つかりません");
return;
}
var thread = threads[0]
var messages = thread.getMessages();
var message = messages[messages.length-1];
var body = message.getBody();
body = body.replace(/<br \/>/g, "");
// Logger.log("message body: " + body);
var teacher = null;
var teacherName = null;
var teacherSkypeName = null;
var reservedDate = null;
var startAt = null;
var date = null;
var startTime = null;
var rows = body.split("\n");
for (var i in rows) {
var row = rows[i];
if (row.indexOf("講師名") === 0) {
teacher = row;
teacherName = teacher.replace("講師名:", "");
Logger.log(teacherName);
} else if (row.indexOf("講師Skype名") === 0) {
teacherSkypeName = row;
} else if (row.indexOf("ご予約日") === 0) {
reservedDate = row;
date = row.replace("ご予約日:", "");
date = date.replace("年", "/");
date = date.replace("月", "/");
date = date.replace("日", "/");
} else if (row.indexOf('開始時間') === 0) {
startAt = row;
startTime = startAt.replace("開始時間:", "");
startTime = startTime.replace("時", ":");
startTime = startTime.replace("分", "");
}
}
var startDateStr = date + " " + startTime;
var startDate = new Date(startDateStr);
var endDate = new Date(startDate);
endDate.setMinutes(endDate.getMinutes() + 25);
Logger.log("startDate: " + startDate);
Logger.log("endDate: " + endDate);
if (teacher && teacherSkypeName && reservedDate && startAt && date) {
var title = "DMM英会話 " + teacherName + "先生";
var contents = [teacher, teacherSkypeName, reservedDate, startAt];
var content = contents.join("\n");
Logger.log(title);
Logger.log(content);
// カレンダーに追加
calendar.createEvent(title, startDate, endDate, {description: content});
thread.markRead();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment