Skip to content

Instantly share code, notes, and snippets.

@ronoaldo
Last active November 29, 2022 18:01
Show Gist options
  • Save ronoaldo/9ca1efa85f083ef5ed2f to your computer and use it in GitHub Desktop.
Save ronoaldo/9ca1efa85f083ef5ed2f to your computer and use it in GitHub Desktop.
Google Apps Script RSS Feed Generator
// O título do Feed
var FEED_TITLE = 'Meu Feed RSS';
// Descrição do Feed
var FEED_DESC = 'Esse é o meu Feed RSS';
// URL do Feed - O padrão aqui é usar a URL do próprio script
var FEED_URL = ScriptApp.getService().getUrl();
// O ID da planilha que vai alimentar o FEED
var SHEET_ID = 'ID DA PLANILHA AQUI';
function doGet(e) {
// Setup
var ss = SpreadsheetApp.openById(SHEET_ID);
data = ss.getSheetByName('Feed').getDataRange().getValues(),
xml = '<?xml version="1.0" encoding="UTF-8"?>';
xml += '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
xml += '<channel><title>' + FEED_TITLE + '</title>';
xml += '<description>' + FEED_DESC + '</description>';
xml += '<link>' + FEED_URL + '</link>';
xml += '<atom:link href="' + FEED_URL + '" rel="self" type="application/rss+xml" />';
// Lookup items from spreadsheet
for (var i=1; i < data.length; i++) {
var title = data[i][0],
link = data[i][1],
desc = data[i][2],
pubDate = data[i][3];
xml += '<item>';
xml += '<title>' + title + '</title>';
xml += '<link>' + link + '</link>';
xml += '<description>' + desc + '</description>';
xml += '<pubDate>' + new Date(pubDate).toUTCString() + '</pubDate>';
xml += '<guid>' + makeGUID(i) + '</guid>';
xml += '</item>';
}
xml += '</channel></rss>';
var response = ContentService.createTextOutput(xml)
response.setMimeType(ContentService.MimeType.RSS);
return response
}
function makeGUID(pos) {
if (FEED_URL.indexOf('?') > 0) {
return FEED_URL += '&guid=' + pos;
}
return FEED_URL + '?guid=' + pos;
}
@ancmto
Copy link

ancmto commented Nov 29, 2022

Eu fiz a inserção desse código, mas não funcionou.

var xml = createXmlFromSheet();
var file = DriveApp.createFile("meuarquivo.xml", xml.toString(), "text/xml");
console.log(Arquivo gerado em ${file.getDownloadUrl()});

Captura de ecrã 2022-11-29, às 20 00 49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment