0
2

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 3 years have passed since last update.

109シネマズの予約情報をGoogleカレンダーに登録

Posted at

はじめに

この投稿はTOHOシネマズの予約情報をGoogleカレンダーに登録の109シネマズ版です。
設定方法などはTOHOシネマズ版と同じなので上の記事を参考にしていただき、
この記事ではソースコードだけ公開します。

ソースコード

function create109EventFromGmail(){
  var calendar = CalendarApp.getDefaultCalendar();
  var start = 0;
  var max = 1;
  var event_length = 120; // 終了時間はわからないので120分で固定
  // タイトル名を検索
  var threads = GmailApp.search('109シネマズ チケットご購入完了のお知らせ',start,max);
  
  for(var i in threads){
    var thread = threads[i];
    var msgs = thread.getMessages();
    
    for(var j in msgs){
      var msg = msgs[j];
      var body = msg.getPlainBody();
      if (body == "") continue;
      
      // 情報を取得
      var id = body.match(/購入番号:(\d+)/)[1];
      var date = body.match(/上映日 :(\d+\/\d+\/\d+)/)[1];
      var time_from = body.match(/上映時間:(\d+:\d+)/)[1];
      var cinema = body.match(/劇場名 :(.*)/)[1];
      var theater = body.match(/上映劇場:(.*)/)[1];
      var name = body.match(/上映作品:(.*)/)[1];
      var seat = body.match(/座席  :(.*)/)[1];
      
      theater = cinema + " " + theater

      var start_date_time = new Date(date+" "+time_from+":00");
      var end_date_time = new Date(date+" "+time_from+":00");
      end_date_time.setMinutes(start_date_time.getMinutes() + event_length);

      Logger.log("ID: " + id);
      Logger.log("Date: " + date);
      Logger.log("Time: " + time_from + "");
      Logger.log("Theater: " + theater);
      Logger.log("Name: " + name);
      Logger.log("Seat: " + seat);

      // 既存予定有無確認
      var registed_events = calendar.getEvents(start_date_time, end_date_time, {search: "["+id+"]"+name});
      if(registed_events.length == 0) {
        // Googleカレンダーへの投稿
        var options = {
          description: body,
          location: theater
        };
        
        var event = calendar.createEvent("["+id+"]"+name,
                                            start_date_time,
                                            end_date_time,
                                            options);
        Logger.log("Calendar Registered: " + event.getId());
      } else {
        Logger.log("Already registered. (count:"+registed_events.length+") ("+registed_events[0].getTitle()+")");
      }
      Logger.log("----------------------------------");
    }
  }
}

109シネマズは会員になると、エグゼクティブシートに無料でアップグレードできるのが良いですね!

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?