Last active
December 7, 2019 19:47
-
-
Save dora1998/ba99368e26a7d236f9b87b5fb34a6c66 to your computer and use it in GitHub Desktop.
メールからカレンダーに登録するやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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