Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function doGet() {
- // Gather all the data from the spreadsheet and set to variables
- var ss = SpreadsheetApp.openByUrl(
- 'https://docs.google.com/spreadsheets/d/1lPOwiYGBK0kSJXXU9kaQjG7WNHjnNuxy25WCUudE5sk/edit');
- SpreadsheetApp.setActiveSpreadsheet(ss);
- SpreadsheetApp.setActiveSheet(ss.getSheets()[0]);
- var title = ss.getSheets()[0].getRange("A1:A").getValues();
- var titles = [];
- var link = ss.getSheets()[0].getRange("B1:B").getValues();
- var links = [];
- var pubdate = ss.getSheets()[0].getRange("C1:C").getValues();
- var pubdates = [];
- var description = ss.getSheets()[0].getRange("D1:D").getValues();
- var descriptions = [];
- var author = ss.getSheets()[0].getRange("E1:E").getValues();
- var authors = [];
- //Create loop to modifiy all variables with their xml tags for RSS
- for (i = 0; i < title.length; i++) {
- titles += "<item>" + "<title>" + title[i] + "</title>";
- }
- for (i = 0; i < link.length; i++) {
- links += "<link>" + link[i] + "</link>";
- }
- for (i = 0; i < pubdate.length; i++) {
- pubdates += "<pubdate>" + pubdate[i] + "</pubdate>";
- }
- for (i = 0; i < description.length; i++) {
- descriptions += "<description>" + description[i] + "</description>";
- }
- for (i = 0; i < author.length; i++) {
- authors += "<author>" + author[i] + "</author>" + "</item>";
- }
- //Combine the variables to desired pattern output
- var all = [titles,links,descriptions,pubdates,authors];
- var mix = [];
- // after running the above loop mix will have the following contents:
- for (var i = 0; all.length !== 0; i++) {
- var j = 0;
- while (j < all.length) {
- if (i >= all[j].length) {
- all.splice(j, 1);
- } else {
- mix.push(all[j][i]);
- j += 1;
- }
- }
- }
- //Print data and set mimetype
- return ContentService.createTextOutput(mix)
- .setMimeType(ContentService.MimeType.RSS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement