Skip to content

Instantly share code, notes, and snippets.

@FirePanther
Last active November 17, 2016 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FirePanther/ac875dfac1e77bb3ff8c to your computer and use it in GitHub Desktop.
Save FirePanther/ac875dfac1e77bb3ff8c to your computer and use it in GitHub Desktop.
Google Apps Script
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