Results 1 to 4 of 4

Thread: Display and sort messages based on a total, not distributed equally among the feeds.

  1. #1
    Join Date
    Mar 2015
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Display and sort messages based on a total, not distributed equally among the feeds.

    1) Script Title: gfeedfetcher

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...sdisplayer.htm

    3) Describe problem: I have two feeds. One is updated monthly, the other is updated much more frequently, but pretty randomly.

    What I want is to display and sort the most recent 6 items total - not the most recent 3 from each of the two feeds.

    So I currently have 1 test message in the new monthly feed, (Sales Tax Allocations) and many messages in the original feed (Comptroller News).

    If I set filterfeed to (6, date) I only get 4 messages. The test message from the new feed, then 3 messages from the original feed.

    I will probably never want to display 3 messages from the new feed. The most would be 1 but it could possibly be zero.

    I just want the 6 most recent messages regardless of which feed they are coming from.

    Looking at the gfeedfetcher.js I can see where the code is figuring out how to distribute the messages among the feeds, but I can't figure out how to make it NOT do that. Can someone help?

    The new feed goes live tomorrow. I can bump up the number under filterfeed as a hack for tomorrow, but of course that will break as soon as the second message comes through the Sales Tax Allocations feed.


    Here's the page: http://www.window.state.tx.us/

    but it doesn't have the second feed integrated yet.

    Here's the code from the page on the dev server:

    Code:
    <script type="text/javascript">
    var newsfeed=new gfeedfetcher("feed", "home-feed")
    newsfeed.addFeed("Comptroller News", "https://public.govdelivery.com/topics/TXCOMPT_1007/feed.rss") //Specify "label" plus URL to RSS feed
    newsfeed.addFeed("Sales Tax Allocations", "https://public.govdelivery.com/topics/TXCOMPT_1026/feed.rss")
    newsfeed.displayoptions("datetime label")
    newsfeed.setentrycontainer("li") //Display each entry as a paragraph
    newsfeed.filterfeed(6, "date") //Show 6 entries, sort by date
    newsfeed.init() //Always call this last
    			</script>

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    changes to two functions in red

    Code:
    gfeedfetcher.prototype.init=function(){
    	this.feedsfetched=0 //reset number of feeds fetched to 0 (in case init() is called more than once)
    	this.feeds=[] //reset feeds[] array to empty (in case init() is called more than once)
    	this.feedcontainer.innerHTML='<img src="'+gfeedfetcher_loading_image+'" /> Retrieving RSS feed(s)'
    	var displayer=this
    	for (var i=0; i<this.feedurls.length; i++){ //loop through the specified RSS feeds' URLs
    		var feedpointer=new google.feeds.Feed(this.feedurls[i]) //create new instance of Google Ajax Feed API
    		var items_to_show=25;//(this.feedlimit<=this.feedurls.length)? 1 : Math.floor(this.feedlimit/this.feedurls.length) //Calculate # of entries to show for each RSS feed
    		if (this.feedlimit%this.feedurls.length>0 && this.feedlimit>this.feedurls.length && i==this.feedurls.length-1) //If this is the last RSS feed, and feedlimit/feedurls.length yields a remainder
    			items_to_show+=(this.feedlimit%this.feedurls.length) //Add that remainder to the number of entries to show for last RSS feed
    		feedpointer.setNumEntries(items_to_show) //set number of items to display
    		feedpointer.load(function(label){
    			return function(r){
    				displayer._fetch_data_as_array(r, label)
    			}
    		}(this.feedlabels[i])) //call Feed.load() to retrieve and output RSS feed.
    	}
    }
    Code:
    gfeedfetcher.prototype._displayresult=function(feeds){
    	var rssoutput=(this.containertag[0]=="li")? "<ul>\n" : ""
    	gfeedfetcher._sortarray(feeds, this.sortstring)
    	var itemurl=[], itemtitle=[], itemlabel=[], itemdate=[], itemdescription=[]
    	for (var i=0; i<this.feedlimit; i++){
    		itemurl.push(feeds[i].link)
    		itemtitle.push('<span class="titlefield"><a href="' + feeds[i].link + '" target="' + this.linktarget + '">' + feeds[i].title + '</a></span>\n')
    		itemlabel.push(/label/i.test(this.showoptions)? '<span class="labelfield">'+this.feeds[i].ddlabel+'</span>\n' : "")
    		itemdate.push(gfeedfetcher._formatdate(feeds[i].publishedDate, this.showoptions))
    		var itemdescriptionsingle=/description/i.test(this.showoptions)? feeds[i].content : /snippet/i.test(this.showoptions)? feeds[i].contentSnippet  : ""
    		itemdescriptionsingle=(itemdescriptionsingle!="")? '<span class="descriptionfield">' + itemdescriptionsingle + '</span>\n' : ""
    		itemdescription.push(itemdescriptionsingle)
    	}
     	// create temp object to store references to rss components, for access dynamically:
    	var holder={urlfield: itemurl, titlefield: itemtitle, labelfield: itemlabel, datefield: itemdate, descriptionfield: itemdescription}
    	var regexprules=this.regexprules
    	for (var i=(this.regexprules && this.regexprules.length>0? this.regexprules.length-1 : -1); i>=0; i--){ // loop thru regexprules array
    		if (regexprules[i][2]=="titlefield" || regexprules[i][2]=="labelfield" || regexprules[i][2]=="datefield" || regexprules[i][2]=="descriptionfield"){
    			var targetarray=holder[regexprules[i][2]] // reference array containing said field type (ie: itemdescription if regexprules[i][2]=="descriptionfield")
    			targetarray=targetarray.join('***delimiter***') // combine array elements before doing search and replace
    				.replace(regexprules[i][0], regexprules[i][1])
    				.split('***delimiter***') // revert back to array
    			holder[regexprules[i][2]]=targetarray
    			regexprules.splice(i,1) // remove this rule from regexprules
    		}
    	}
    	for (var i=0; i<this.feedlimit; i++){ // loop thru feeds, molding each feed entry based on template
    		rssoutput+= this.containertag[1] + this.outputtemplate.replace(/({title})|({url})|({label})|({date})|({description})/ig, function(m){
    			if (m == "{title}")
    				return holder.titlefield[i]
    			else if (m == "{url}")
    				return holder.urlfield[i]
    			else if (m == "{label}")
    				return holder.labelfield[i]
    			else if (m == "{date}")
    				return holder.datefield[i]
    			else if (m == "{description}")
    				return holder.descriptionfield[i]
    		}) + "</" + this.containertag[0] + ">" + "\n\n"
    	}
    	rssoutput+=(this.containertag[0]=="li")? "</ul>" : ""
    	for (var i=0; i<this.regexprules.length; i++){ // loop thru remaining regexprules array that target the entire feed in general (versus specific field)
    		rssoutput=rssoutput.replace(this.regexprules[i][0], this.regexprules[i][1])
    	}
    	this.feedcontainer.innerHTML=rssoutput
    }
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Mar 2015
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Thank you!!!

    Thank you very much!

    One question though. Why items_to_show=25 ?

    Just some randomly large number?

  4. #4
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Just some randomly large number?

    yes
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Similar Threads

  1. Display multiple RSS feeds based on a keyword using gAjax RSS v2
    By TennisWill in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 03-06-2013, 06:40 PM
  2. Replies: 0
    Last Post: 09-05-2011, 09:18 AM
  3. sort rss by date (gAjax RSS Feeds Displayer)
    By mimewear in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 08-09-2010, 12:15 AM
  4. gAjax RSS Feeds Displayer Sort?
    By lrickyutah in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 10-04-2008, 06:13 PM
  5. gAjax RSS Feeds Displayer - can't display multiple feeds
    By nsbrown in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 06-06-2008, 08:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •