Skip to content

Instantly share code, notes, and snippets.

@dora1998
Last active December 7, 2019 19:47
Show Gist options
  • Save dora1998/ba99368e26a7d236f9b87b5fb34a6c66 to your computer and use it in GitHub Desktop.
Save dora1998/ba99368e26a7d236f9b87b5fb34a6c66 to your computer and use it in GitHub Desktop.
メールからカレンダーに登録するやつ
function checkMovixEmail() {
var searchQuery = "from:([email protected]) subject:(チケット購入の確認)";
var checkSpanMinute= 5; // 起動時間間隔
const regexpObj = /[\s]+(.+)[\s]+(.+)[\s]+[\s]+(.+)[\s]+[\s]+([0-9]+\/[0-9]+\/[0-9]+).+[\s]+([0-9]+:[0-9]+)([0-9]+:[0-9]+)[\s\S]+login.do/m
var dt = new Date();
dt.setMinutes(dt.getMinutes() - checkSpanMinute);
var threads = GmailApp.search(searchQuery, 0, 5);
var msgs = GmailApp.getMessagesForThreads(threads);
for(var i = 0; i < threads.length; i++) {
var lastMsgDt = threads[i].getLastMessageDate();
if(lastMsgDt.getTime() < dt.getTime()) {
break;
}
for(var j = 0; j < msgs[i].length; j++) {
var msgBody = msgs[i][j].getPlainBody();
var matches = msgBody.match(regexpObj)
Logger.log(matches)
if (!matches) continue;
var place = matches[1]
var theater = matches[2]
var movieName = matches[3]
var reservationDate = matches[4]
var startTime = matches[5]
var endTime = matches[6]
var event = CalendarApp.getDefaultCalendar().createEvent(movieName,
new Date(reservationDate + ' ' + startTime),
new Date(reservationDate + ' ' + endTime),
{description: matches[0],
location: place + ' ' + theater});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment