Created
August 26, 2016 14:24
-
-
Save m4p/1f2ce49e07e4f6f5610f16ad8a0fa63c 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); | |
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