Advertisement
hakarune

AppScript Code Version 2

Jun 19th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. function doGet() {
  2. // Gather all the data from the spreadsheet and set to variables
  3. var ss = SpreadsheetApp.openByUrl(
  4. 'https://docs.google.com/spreadsheets/d/1lPOwiYGBK0kSJXXU9kaQjG7WNHjnNuxy25WCUudE5sk/edit');
  5. SpreadsheetApp.setActiveSpreadsheet(ss);
  6. SpreadsheetApp.setActiveSheet(ss.getSheets()[0]);
  7. var title = ss.getSheets()[0].getRange("A1:A").getValues();
  8. var titles = [];
  9. var link = ss.getSheets()[0].getRange("B1:B").getValues();
  10. var links = [];
  11. var pubdate = ss.getSheets()[0].getRange("C1:C").getValues();
  12. var pubdates = [];
  13. var description = ss.getSheets()[0].getRange("D1:D").getValues();
  14. var descriptions = [];
  15. var author = ss.getSheets()[0].getRange("E1:E").getValues();
  16. var authors = [];
  17. //Create loop to modifiy all variables with their xml tags for RSS
  18. for (i = 0; i < title.length; i++) {
  19. titles += "<item>" + "<title>" + title[i] + "</title>";
  20. }
  21. for (i = 0; i < link.length; i++) {
  22. links += "<link>" + link[i] + "</link>";
  23. }
  24. for (i = 0; i < pubdate.length; i++) {
  25. pubdates += "<pubdate>" + pubdate[i] + "</pubdate>";
  26. }
  27. for (i = 0; i < description.length; i++) {
  28. descriptions += "<description>" + description[i] + "</description>";
  29. }
  30. for (i = 0; i < author.length; i++) {
  31. authors += "<author>" + author[i] + "</author>" + "</item>";
  32. }
  33.  
  34. //Combine the variables to desired pattern output
  35.  
  36. var all = [titles,links,descriptions,pubdates,authors];
  37. var mix = [];
  38. // after running the above loop mix will have the following contents:
  39.  
  40.  
  41. for (var i = 0; all.length !== 0; i++) {
  42. var j = 0;
  43. while (j < all.length) {
  44. if (i >= all[j].length) {
  45. all.splice(j, 1);
  46. } else {
  47. mix.push(all[j][i]);
  48. j += 1;
  49. }
  50. }
  51. }
  52.  
  53. //Print data and set mimetype
  54. return ContentService.createTextOutput(mix)
  55. .setMimeType(ContentService.MimeType.RSS);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement