Modifying a Feed.

Posted: August 14, 2014 in Digital Media, links, Writing/Rambling
Tags: , , , ,

A script I wrote back in the day, when Yahoo pipes worked, might use it again some day. It can take something like an RSS feed and replace some strings.

The script (Javascript, AJAX, HTML):

 $(document).ready(function(){
function loadOnSale(){ // Just make the page say 'Loading' until script is ready.
$('#onSale').html('Loading');
$.ajax({
type: "GET",
dataType: "json", //the URL to pull the feed from, Render as json. url: "http://pipes.yahoo.com/pipes/pipe.run?_id=104896d8a0cb89e530b59e405e3208ff&_render=json", // I'm not sure I needed everything in the next six lines? async: true,
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
success:function(feed) {
// Make the Header. And then 'for each' item in feed, up to 16 times, we'll make some variables and append a product div
$('#onSale').html('<h3>Now On Sale:</h3>');
for(var i=0, l=feed.value.items.length; i < l && i < 16; i++)
{
// Replace one string of text with another var img = feed.value.items[i].description.replace("String of Text.","New string of text.");
var thisItem= feed.value.items[i];
var title= thisItem["y:title"];
var description= feed.value.items[i].description; // Add the new element to an array or HTML page.
$('#onSale').append("div class='product'div class='productImage'"+title+""+img+"/div/div");
}
},
});
};
// Yup all those different '"}); had to work just right for HTML... it was a headache. //Start the script
loadOnSale();
});
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s