index.js
function parseGoogleNewsRSSData(fileData) {
    // sanity check that this is valid google news RSS
    if (fileData.indexOf('news-feedback@google.com') != -1) {
        // set an empty array of news story objects
        var allGoogleNewsData = [ ];
        var params = {normalizeWhitespace: true, xmlMode: true};
        // load the html into the cheerio doc
        var cheerio = require("cheerio");
        var fullDoc = cheerio.load(fileData, params);    
        // iterate through movies and strip useful parts, add each to return object
        fullDoc('item').each(function(i, elem) {
            // load current item
            var itemDoc = cheerio.load(fullDoc(this).html(), params);
            // break out parts of interest
            // some sections need cleaning so do that as well
            var fullTitleLine = itemDoc('title').text().trim();
            var fullTitleSplitIndex = fullTitleLine.lastIndexOf(' - ');
            var titlePart = fullTitleLine.substring(0, fullTitleSplitIndex);
            var sourcePart = fullTitleLine.substring(fullTitleSplitIndex + 3, fullTitleSplitIndex.length);
            var fullURLPart = itemDoc('link').html().trim();
            var cleanURLPart = fullURLPart.split(';url=')[1];
            var categoryPart = itemDoc('category').html();
            if (categoryPart != null)
                categoryPart = categoryPart.trim();
            var pubDatePart = itemDoc('pubDate').html().trim();
            var fullDescriptionPart = itemDoc('description').text().trim();
            var descriptionStart = fullDescriptionPart.indexOf('</font><br><font size="-1">');
            var descriptionEnd = fullDescriptionPart.indexOf('</font>', descriptionStart + 1);
            var cleanDescriptionPart = fullDescriptionPart.substring(descriptionStart, descriptionEnd);
            var cleanDescriptionPart = cleanDescriptionPart.replace('</font><br><font size="-1">', '');
            var cleanDescriptionPart = cleanDescriptionPart.replace('<b>...</b>', '...');
            // build final object for the current news story
            var fullObject = {  title: titlePart
                                , source: sourcePart
                                , category: categoryPart
                                , pubDate: pubDatePart
                                , fullURL: fullURLPart
                                , cleanURL: cleanURLPart
                                , fullDescription: fullDescriptionPart
                                , cleanDescription: cleanDescriptionPart
                             };                           
            // add thew news story obejct to the array
            allGoogleNewsData.push(fullObject);            
        });
        // return no error state and the collected news story objects
        return {error: false, data: allGoogleNewsData};
    }
    // if sanity check failed, return true error state and an error message
    return {error: errorFlag, errorMessage: 'Fetched RSS data does not contain expected content.', data: null};
}
function parseGoogleNewsRSSData(fileData) {
    // sanity check that this is valid google news RSS
    if (fileData.indexOf('news-feedback@google.com') != -1) {
        // set an empty array of news story objects
        var allGoogleNewsData = [ ];
        var params = {normalizeWhitespace: true, xmlMode: true};
        // load the html into the cheerio doc
        var cheerio = require("cheerio");
        var fullDoc = cheerio.load(fileData, params);    
        // iterate through movies and strip useful parts, add each to return object
        fullDoc('item').each(function(i, elem) {
            // load current item
            var itemDoc = cheerio.load(fullDoc(this).html(), params);
            // break out parts of interest
            // some sections need cleaning so do that as well
            var fullTitleLine = itemDoc('title').text().trim();
            var fullTitleSplitIndex = fullTitleLine.lastIndexOf(' - ');
            var titlePart = fullTitleLine.substring(0, fullTitleSplitIndex);
            var sourcePart = fullTitleLine.substring(fullTitleSplitIndex + 3, fullTitleSplitIndex.length);
            var fullURLPart = itemDoc('link').html().trim();
            var cleanURLPart = fullURLPart.split(';url=')[1];
            var categoryPart = itemDoc('category').html();
            if (categoryPart != null)
                categoryPart = categoryPart.trim();
            var pubDatePart = itemDoc('pubDate').html().trim();
            var fullDescriptionPart = itemDoc('description').text().trim();
            var descriptionStart = fullDescriptionPart.indexOf('</font><br><font size="-1">');
            var descriptionEnd = fullDescriptionPart.indexOf('</font>', descriptionStart + 1);
            var cleanDescriptionPart = fullDescriptionPart.substring(descriptionStart, descriptionEnd);
            var cleanDescriptionPart = cleanDescriptionPart.replace('</font><br><font size="-1">', '');
            var cleanDescriptionPart = cleanDescriptionPart.replace('<b>...</b>', '...');
            // build final object for the current news story
            var fullObject = {  title: titlePart
                                , source: sourcePart
                                , category: categoryPart
                                , pubDate: pubDatePart
                                , fullURL: fullURLPart
                                , cleanURL: cleanURLPart
                                , fullDescription: fullDescriptionPart
                                , cleanDescription: cleanDescriptionPart
                             };                           
            // add thew news story obejct to the array
            allGoogleNewsData.push(fullObject);            
        });
        // return no error state and the collected news story objects
        return {error: false, data: allGoogleNewsData};
    }
    // if sanity check failed, return true error state and an error message
    return {error: errorFlag, errorMessage: 'Fetched RSS data does not contain expected content.', data: null};
}
function parseGoogleNewsRSSData ( fileData ) { // sanity check that this is valid google news RSS
 if ( fileData . indexOf ( 'news-feedback@google.com' ) != - 1 ) { // set an empty array of news story objects
 var allGoogleNewsData = [ ] ; var params = { normalizeWhitespace : true , xmlMode : true } ; // load the html into the cheerio doc
 var cheerio = require ( "cheerio" ) ; var fullDoc = cheerio . load ( fileData , params ) ; // iterate through movies and strip useful parts, add each to return object
 fullDoc ( 'item' ) . each ( function ( i , elem ) { // load current item
 var itemDoc = cheerio . load ( fullDoc ( this ) . html ( ) , params ) ; // break out parts of interest
 // some sections need cleaning so do that as well
 var fullTitleLine = itemDoc ( 'title' ) . text ( ) . trim ( ) ; var fullTitleSplitIndex = fullTitleLine . lastIndexOf ( ' - ' ) ; var titlePart = fullTitleLine . substring ( 0 , fullTitleSplitIndex ) ; var sourcePart = fullTitleLine . substring ( fullTitleSplitIndex + 3 , fullTitleSplitIndex . length ) ; var fullURLPart = itemDoc ( 'link' ) . html ( ) . trim ( ) ; var cleanURLPart = fullURLPart . split ( ';url=' ) [ 1 ] ; var categoryPart = itemDoc ( 'category' ) . html ( ) ; if ( categoryPart != null ) categoryPart = categoryPart . trim ( ) ; var pubDatePart = itemDoc ( 'pubDate' ) . html ( ) . trim ( ) ; var fullDescriptionPart = itemDoc ( 'description' ) . text ( ) . trim ( ) ; var descriptionStart = fullDescriptionPart . indexOf ( '</font><br><font size="-1">' ) ; var descriptionEnd = fullDescriptionPart . indexOf ( '</font>' , descriptionStart + 1 ) ; var cleanDescriptionPart = fullDescriptionPart . substring ( descriptionStart , descriptionEnd ) ; var cleanDescriptionPart = cleanDescriptionPart . replace ( '</font><br><font size="-1">' , '' ) ; var cleanDescriptionPart = cleanDescriptionPart . replace ( '<b>...</b>' , '...' ) ; // build final object for the current news story
 var fullObject = { title : titlePart , source : sourcePart , category : categoryPart , pubDate : pubDatePart , fullURL : fullURLPart , cleanURL : cleanURLPart , fullDescription : fullDescriptionPart , cleanDescription : cleanDescriptionPart } ; // add thew news story obejct to the array
 allGoogleNewsData . push ( fullObject ) ; } ) ; // return no error state and the collected news story objects
 return { error : false , data : allGoogleNewsData } ; } // if sanity check failed, return true error state and an error message
 return { error : errorFlag , errorMessage : 'Fetched RSS data does not contain expected content.' , data : null } ; }
parses the data returned from the RSS request returns the data object sent back via the callback
parses the data returned from the RSS request returns the data object sent back via the callback