Skip to content

Instantly share code, notes, and snippets.

@yoshimov
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save yoshimov/9363009 to your computer and use it in GitHub Desktop.

Select an option

Save yoshimov/9363009 to your computer and use it in GitHub Desktop.
Notify specific web page periodically using GAS
function notifyIssues() {
var issueurl = PropertiesService.getScriptProperties().getProperty("issueurl");
var toaddress = PropertiesService.getScriptProperties().getProperty("mailaddress");
var httpuser = PropertiesService.getScriptProperties().getProperty("httpuser");
var httppass = PropertiesService.getScriptProperties().getProperty("httppassword");
var subject = PropertiesService.getScriptProperties().getProperty("subject");
var header = PropertiesService.getScriptProperties().getProperty("header");
var passenc = Utilities.base64Encode(httpuser + ":" + httppass);
var response = UrlFetchApp.fetch(issueurl, {"headers": {"Authorization": "Basic " + passenc}});
var content = response.getContentText();
var bodyIndex = content.indexOf("wiki-body");
var listIndex = content.indexOf("<hr", bodyIndex) + 6;
var bodyEnd = content.indexOf("</div>", listIndex);
var listContent = content.substring(listIndex, bodyEnd).trim();
if (listContent && listContent.length > 0) {
// send mail
MailApp.sendEmail(toaddress, "", subject, header + listContent + "<p><a href=\"" + issueurl + "\">" + issueurl + "</a></p>");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment