Tuesday, February 20, 2007

Example of grouping common RSS feeds together using /n software products

I visit the PowerGadgets forums quite a bit to see what's going on, and ask questions (as "fedrac").  I had recently asked PowerGadgets to enable RSS feeds to the forum, and seeing as they are using Community Server, this apparently was pretty easy to do.

One thing annoyed me slightly: there are 2 kinds of feeds:

1. There are feeds to each discussion forum.  This feed only presents the new *threads* in the forum.

2. There are feeds to each thread.  This feed only presents the new *posts* to the thread.

So signing up to a forum is easy, but if you're interested in seeing *all* of the activity, you also need to sign up to each thread.  That's a lot of work, and needed a PowerShell solution!

I had a vision of my end goal, but wanted to try a solution just using PowerShell, PSCX's feedstoreprovider, and IE7's RSS features.  I spent way too much time on that though.

Then, I decided to go straight for what I was envisioning...  Using /n software's RSSBus (free desktop version!) to find a way to *combine* all the PowerGadgets feeds for forums and threads in one single RSS feed.

So, to accomplish this, first I wrote a PowerShell script using /n software's NetCmdlets (free desktop version!) and their get-rss cmdlet.  This script goes and grabs the forums' feeds, and from that gets all the threads within each feed.  It creates a dynamic RSBScript (scripting language for RSSBus), that then is copied to RSSBus' working directory.

Here's my PowerShell script:

$ErrorActionPreference="silentlycontinue"

$feed_script="C:\rssbus\www\powergadgets.rsb"

if(test-path $feed_script){
  remove-item $feed_script
}

$j=1

$rss_feeds=@("http://powergadgets.com/csPg/forums/rss.aspx?ForumID=4&Mode=0",
"http://powergadgets.com/csPg/forums/rss.aspx?ForumID=5&Mode=0",
"http://powergadgets.com/csPg/forums/rss.aspx?ForumID=6&Mode=0",
"http://powergadgets.com/csPg/forums/rss.aspx?ForumID=14&Mode=0")

$rss_url="http://powergadgets.com/csPg/forums/rss.aspx?ForumID="

$threads=@()

for($i=0;$i -lt $rss_feeds.count;$i++){
  $threads+=(get-rss $rss_feeds[$i]|%{$forum=$rss_feeds[$i].split('/.=&')[8];$thread=$_.link.split('/.')[7];${rss_url}+${forum}+"&PostID="+${thread}})
}

$rss_feeds+=$threads

$rss_feeds+="http://powergadgets.com/csPg/blogs/MainFeed.aspx"

$rss_feeds|?{$_ -notmatch "^$"}|%{add-content $feed_script "<rsb:set item=`"input`" attr=`"feed#$j`" value=`"$_`" />"$j++}
add-content $feed_script "<rsb:call op=`"rsbFeedUnion`" in=`"input`">"
add-content $feed_script "<rsb:push />"
add-content $feed_script "</rsb:call>"

$ErrorActionPreference="continue"

[end PowerShell script]

I cheat a little bit by setting the error preferences.  Seems there's some extra spaces and strage things going on that cause some errors to the screen.

Now, one can easily call the RSBScript I created, and register it as an RSS feed in their favorite RSS feed viewer.

It's as easy as using this as the RSS feed address when you have RSSBus installed:

http://localhost:1110/powergadgets.rsb

The above RSBScript still needs a little bit of fine tuning to get the name of the feed to something more meaningful, but the guts of the requirements are there.

(I really have to figure out how to properly format code in blogspot...)