3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

DMM英会話とレアジョブ英会話で予約をした時に自動で予定をGoogleカレンダーに追加するGAS

Last updated at Posted at 2022-10-02

DMM英会話とレアジョブ英会話で,予約したら自動でカレンダーに追加できないかなーと思い調べたところこちらの記事(2022/10/3アクセス)を見つけました.レアジョブ英会話用のコードは1分探して見つからなかったので筆者が適当に変更したものを共有したいと思います.

DMM英会話用(カレンダーの予定の色が変わるように参考元から少し変更)

var CRITERIA = "from:noreply@eikaiwa.dmm.com subject:レッスン予約 is:unread ";

function main() {
  eachMessage(CRITERIA, function (message) {
    var cal = CalendarApp.getDefaultCalendar();
    var body = message.getBody();    
    var [phrase] = /様、.*とのレッスン予約が完了しました/.exec(body);
    var [str] = phrase.match(/\d{4}\/\d{2}\/\d{2}\ \d{2}\:\d{2}/g);

    var title = "DMM英会話";
    var startTime = new Date(str);
    var endTime = new Date(startTime.getTime() + 25 * 60000);

    var event = cal.createEvent(title, startTime, endTime);
    event.setColor(CalendarApp.EventColor.PALE_RED)
  });
}

function eachMessage(CRITERIA, callback) {
  GmailApp.search(CRITERIA).forEach(function(thread) {
    thread.getMessages().forEach(function(message) {
      callback(message);
      message.markRead(); 
    });
  });
}

レアジョブ英会話用

var CRITERIA = "from:donotreply@rarejob.com subject:レッスン予約完了 is:unread ";

function main() {
  eachMessage(CRITERIA, function (message) {
    var cal = CalendarApp.getDefaultCalendar();
    var body = message.getBody();    
    var [phrase] = /予約日時.*表記/.exec(body);
    var [str1] = phrase.match(/\d{4}\/\d{2}\/\d{2}/g);
    var [str2] = phrase.match(/\ \d{2}\:\d{2}/g);
    var str = str1 + str2;

    var title = "レアジョブ英会話";
    var startTime = new Date(str);
    var endTime = new Date(startTime.getTime() + 25 * 60000);

    var event = cal.createEvent(title, startTime, endTime);
    event.setColor(CalendarApp.EventColor.PALE_RED)
  });
}

function eachMessage(CRITERIA, callback) {
  GmailApp.search(CRITERIA).forEach(function(thread) {
    thread.getMessages().forEach(function(message) {
      callback(message);
      message.markRead(); 
    });
  });
}
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?