Skip to content

Instantly share code, notes, and snippets.

@7m4kpv 7m4kpv/dmmEikaiwa.js forked from toshiaki-h/dmmEikaiwa.js
Last active Dec 30, 2019

Embed
What would you like to do?
DMM英会話スケジュール自動登録スクリプト
/*
* DMM英会話のスケジュールを登録する
*/
var CALENDAR_NAME = 'YourCorenderName@gmail.com';
var SEARCH_QUERY = 'is:unread subject:"Lesson Booking"';
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 teacherName = null;
var date = null;
var startTime = null;
var rows = body.split("\n");
for (var i in rows) {
var row = rows[i];
if(row.indexOf("Hi") > 0){
Logger.log(row.indexOf("Teacher"));
var mailtext=row;
Logger.log(mailtext);
teacherName = mailtext.slice(row.indexOf("Teacher"),row.indexOf("for"));
Logger.log(teacherName);
date = mailtext.slice(row.indexOf("for")+4,row.indexOf("."));
Logger.log(date);
startTime= date.slice(-5);
Logger.log(startTime);
}
}
var startDateStr = date;
var startDate = new Date(startDateStr);
var endDate = new Date(startDate);
endDate.setMinutes(endDate.getMinutes() + 25);
Logger.log("startDate: " + startDate);
Logger.log("endDate: " + endDate);
if (teacherName && date) {
var title = "DMM英会話 " + teacherName;
var contents = [teacherName, date, startTime];
var content = contents.join("\n");
Logger.log(title);
Logger.log(content);
// カレンダーに追加
calendar.createEvent(title, startDate, endDate, {description: content}).setColor(10);
thread.markRead();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.