Apps Script trigger - check dane.gov.pl/source-code and send email if new version
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 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; | |
} |
Author
olekstomek
commented
Feb 19, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment