Skip to content

Instantly share code, notes, and snippets.

@olekstomek
Last active Apr 22, 2022
Embed
What would you like to do?
Apps Script trigger - check dane.gov.pl/source-code and send email if new version
function checkDaneGovPlSourceCode() {
const scrappedTextFromWebsite = UrlFetchApp.fetch('https://dane.gov.pl/source-code/').getContentText();
if (scrappedTextFromWebsite.includes(formatDate(new Date()))) {
MailApp.sendEmail({
to: "my@e-mail.com",
subject: "Nowa wersja kodu dane.gov.pl!",
htmlBody: scrappedTextFromWebsite + "</ br> https://dane.gov.pl/source-code/"
});
Logger.log('E-mail was sent.');
} else {
Logger.log('E-mail was not sent.');
}
}
function formatDate(value) {
let date = new Date(value);
const day = date.toLocaleString('en-US', { day: '2-digit' });
const month = date.toLocaleString('en-US', { month: 'short' });
const year = date.toLocaleString('en-US', { year: 'numeric' });
let dateToCheck = day + '-' + month + '-' + year;
Logger.log('dateToCheck = ' + dateToCheck);
return dateToCheck;
}
@olekstomek
Copy link
Author

olekstomek commented Feb 19, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment