Last active
November 17, 2016 04:08
-
-
Save FirePanther/ac875dfac1e77bb3ff8c to your computer and use it in GitHub Desktop.
Google Apps Script
This file contains 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 myFunction() { | |
var calendar = CalendarApp.getCalendarsByName('[a] delivery')[0], | |
threads = GmailApp.search('from:versandbestaetigung@amazon.de'), | |
msg, matchDate, matchProduct, | |
months = [ 'jan', 'feb', 'mär', 'apr', 'mai', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dez' ], | |
delivDay, delivMonth, delivYear; | |
Logger.log("Threads: " + threads.length); | |
for (var x in threads) { | |
Logger.log("Found thread: " + threads[x].getFirstMessageSubject()); | |
msg = threads[x].getMessages(); | |
matchDate = msg[0].getPlainBody().match(/Lieferung voraussichtlich:\s+\S+,\s*(\d+).*?(\w{3})/); | |
delivYear = msg[0].getDate().getFullYear(); | |
if (matchDate !== null) { | |
delivDay = matchDate[1]; | |
for (var i = 0; i < months.length; i++) { | |
if (matchDate[2].toLowerCase() == months[i]) { | |
delivMonth = i; | |
break; | |
} | |
} | |
if (delivMonth < new Date().getMonth()) delivYear++; | |
matchProduct = msg[0].getPlainBody().match(/Einzelheiten Ihrer Lieferung:\s+(\S.*)\s*([\s\S]*?)===============/); | |
if (matchProduct !== null) { | |
Logger.log(matchProduct[1]); | |
calendar.createAllDayEvent( | |
matchProduct[1], | |
new Date(delivYear, delivMonth, delivDay), | |
{ description: matchProduct[2] }); | |
msg[0].markRead().moveToTrash(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment