zondag 17 november 2019

RSS-feed on GAS with GAS

To get grip on Google Apps Script (GAS) I have started to collect information on GAS in a Google spreadsheet by scraping websites, blogs and emails.

The intention is to import the information, provided with relevant labels, into a Google document.

For now I have decided to make a RSS-feed of the information with help of this tutorial of Amit Agarwal (I don't know if the sort function works properly)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
DATA_HEADER = ["today","date","author","title","twitter-hashtag","link"];
RSS_TITEL ="RSS GAS en Javascript";
RSS_DESCRIPTION = "Collectie van blogs met informatie over Google Apps Script en Javascript";
RSS_LINK = "https://scriptjes.blogspot.com/";

function doGet(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Data");  
  var eersterij = sheet.getLastRow() - 14;
  var bereik = sheet.getRange(eersterij,1,15,6).getValues();
  
  bereik.sort(function (a, b){return a[0] - b[0];}).reverse();
  
  var xml = '<rss version="2.0">';
  xml += '<channel>';
  xml += '<title>' + RSS_TITEL + '</title>';
  xml += '<description>' + RSS_DESCRIPTION + '</description>';
  xml += '<link>' + RSS_LINK + '</link>';
  
  for (var i=0;i<bereik.length;i++) {
    xml += '<item>';
    xml += '<title><![CDATA[' + bereik[i][3] + ']]></title>';
    xml += '<link>' + bereik[i][5] + '</link>';
    xml += '<pubDate>' + bereik[i][1].toUTCString() + '</pubDate>';
    xml += '</item>';
  }
  
  xml += '</channel>';
  xml += '</rss>';
  
  return ContentService.createTextOutput(xml).setMimeType(ContentService.MimeType.RSS);
}

Source: Digital Inspiration, Parse RSS Feeds with Google Apps Script


Geen opmerkingen:

Een reactie posten