Skip to content

Instantly share code, notes, and snippets.

@thomo
Created February 11, 2019 20:05
Show Gist options
  • Save thomo/cae8c7c13b14e330726ca3dd74e1293f to your computer and use it in GitHub Desktop.
Save thomo/cae8c7c13b14e330726ca3dd74e1293f to your computer and use it in GitHub Desktop.
Patch retired Yahoo yql API in MagicMirror v1
//jQuery extension to fetch an rss feed and return it as json via YQL
//created by dboz@airshp.com
(function($) {
$.extend({
feedToJson: function(options, callback) {
if ($.isFunction(options)) {
callback = options;
options = null;
}
options = $.extend($.feedToJson.defaults,options);
var url = options.yqlURL + options.yqlQS + encodeURIComponent(options.feed) ;
return $.getJSON(url, function(data){
// console.log(data);
data.item = data.items;
$.isFunction(callback) && callback(data); //allows the callback function to be the only option
$.isFunction(options.success) && options.success(data);
});
}
});
//defaults
$.feedToJson.defaults = {
yqlURL : 'https://api.rss2json.com/v1/api.json', //yql
yqlQS : '?rss_url=', //yql query string
feed:'http://instagr.am/tags/tacos/feed/recent.rss', //instagram recent posts tagged 'tacos'
cachebuster: Math.floor((new Date().getTime()) / 1200 / 1000), //yql caches feeds, so we change the feed url every 20min
success:null //success callback
};
})(jQuery);
// eo feedToJson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment