hakarune

AppScript Code Version 3

Jun 21st, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 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>" + "\n";
  20. }
  21. for (i = 0; i < link.length; i++) {
  22. links += "<link>" + link[i] + "</link>" + "\n";
  23. }
  24. for (i = 0; i < pubdate.length; i++) {
  25. pubdates += "<pubdate>" + pubdate[i] + "</pubdate>" + "\n";
  26. }
  27. for (i = 0; i < description.length; i++) {
  28. descriptions += "<description>" + description[i] + "</description>" + "\n";
  29. }
  30. for (i = 0; i < author.length; i++) {
  31. authors += "<author>" + author[i] + "</author>" + "\n" + "</item>" + "\n";
  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 n=0;n<titles.length;n++){
  42. mix.push(titles[n],links[n],descriptions[n],pubdates[n],authors[n]);
  43. }
  44.  
  45. //Print data and set mimetype
  46. return ContentService.createTextOutput(mix)
  47. .setMimeType(ContentService.MimeType.RSS);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment