Retrieving Release Notes of Google Apps Script and Google APIs from RSS using Google Apps Script

Gists

This is a sample script for retrieving the release notes of Google Apps Script and Google APIs from RSS using Google Apps Script.

Recently, the release notes of Google Apps Script and Google APIs have been published as RSS. By this, the data got to be able to be easily retrieved using XmlService of Google Apps Script. Knowing the latest release notes will be useful for developing the applications. So, I would like to introduce the sample script for retrieving this information.

Sample script

Please copy and paste the following script to the script editor of Google Spreadsheet. And please set the variables in main function.

function getData_({ urls, before }) {
  const date = new Date();
  date.setDate(date.getDate() - before);
  const dateUnix = date.getTime();
  const reqs = urls.map((url) => ({ url, muteHttpExceptions: true }));
  const res = UrlFetchApp.fetchAll(reqs);
  const values = res.reduce((ar, r) => {
    if (r.getResponseCode() == 200) {
      const xml = XmlService.parse(r.getContentText());
      const root = xml.getRootElement();
      const ns = root.getNamespace();
      const updated = new Date(root.getChild("updated", ns).getValue());
      if (updated.getTime() > dateUnix) {
        const title = root.getChild("title", ns).getValue();
        const entries = root.getChildren("entry", ns).map((e) => {
          const updated = new Date(e.getChild("updated", ns).getValue());
          const href = e.getChild("link", ns).getAttribute("href").getValue();
          const content = e.getChild("content", ns).getValue().trim();
          return [updated, href, content];
        });
        ar = [...ar, ...entries.map((e) => [title, updated, ...e])];
      }
    }
    return ar;
  }, []);
  return values;
}

function putValuesToSpreadsheet_({ values, sheetName }) {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  sheet
    .clearContents()
    .getRange(sheet.getLastRow() + 1, 1, values.length, values[0].length)
    .setValues(values);
}

// Please run this function.
function main() {
  const urls = [
    "https://developers.google.com/feeds/apps-script-release-notes.xml",
    "https://developers.google.com/feeds/drive-release-notes.xml",
    "https://developers.google.com/feeds/sheets-release-notes.xml",
    "https://developers.google.com/feeds/docs-release-notes.xml",
    "https://developers.google.com/feeds/slides-release-notes.xml",
    "https://developers.google.com/feeds/forms-release-notes.xml",
    "https://developers.google.com/feeds/calendar-release-notes.xml",
    "https://developers.google.com/feeds/gmail-release-notes.xml",
  ];
  const before = 30; // In this sample, the data from 30 days ago to now is retrieved.
  const sheetName = "Sheet1"; // Please set your sheet name.
  const values = getData_({ urls, before });
  putValuesToSpreadsheet_({ values, sheetName });
}

Testing

In this test, the script is run with before = 2000 because in ths current stage, the number of data is small. When this script is run with before = 2000, the following result is obtained.

Retrieving Release Notes of Google Apps Script and Google APIs from RSS using Google Apps Script

Note

 Share!