Created
August 27, 2016 17:21
-
-
Save m4p/af47ac3bcbe51595781603f83a8770b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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).getContentText(); | |
regex = new RegExp(/<div class="item">[\s\S]*?<a href="([^"]+)[\s\S]*?<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 += "<guid>" + vialink[1] + "</guid>"; | |
rss += "<link>" + vialink[2] + "</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