Skip to content

Instantly share code, notes, and snippets.

@m4p
Created August 26, 2016 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4p/1f2ce49e07e4f6f5610f16ad8a0fa63c to your computer and use it in GitHub Desktop.
Save m4p/1f2ce49e07e4f6f5610f16ad8a0fa63c to your computer and use it in GitHub Desktop.
function Twitter_RSS() {
return;
}
function doGet(e) {
var widgetID = e.queryString? e.queryString : "ERROR_NO_ID_FOUND";
var cache = CacheService.getPublicCache();
var id = "Twitter" + widgetID;
var rss = cache.get(id);
if ( ! rss ) {
rss = getTweets(widgetID);
cache.put(id, rss, 120); // Expire in 2 minutes
}
return ContentService.createTextOutput(rss)
.setMimeType(ContentService.MimeType.XML);
}
function getTweets() {
try {
url = "http://belong.io";
widget = UrlFetchApp.fetch(url);
regex = new RegExp(/<span class="item-via"><a href="([^"]+)/ig);
rss = '<?xml version="1.0"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
rss += ' <channel><title>Just the tweets on belong.io</title>';
while ((vialink = regex.exec(widget)) !== null) {
rss += "<item>";
rss += "<link>" + vialink[1] + "</link>";
rss += "</item>";
}
rss += "</channel></rss>";
return rss;
} catch (e) {
Logger.log(e.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment