Entries Tagged as ''

RSS Aggregation with Google Tutorial

I wanted to add some good content to my website to hopefully attract some traffic. The best way I can think of getting good free content is by using RSS feeds. But how do you get what you want on your site and keep it updated dynamically?

Well I have been playing around with Google Reader recently, and thought someone out there may want to know what I’ve been doing?

Some first thing you are going to need is a Google account so that you can access Google Reader, once you are logged in just go to http://www.google.com/reader to set it up.

In this tutorial I am going to be combining the ITV and Official Formula 1 RSS feeds, you can get these here:

http://www.itv-f1.com/rss/

http://www.formula1.com/rss/news/latest.rss

So add these feeds in to Google Reader

Now that you have added the feeds to aggregate you will want to group them in a folder. This is done in the subscriptions screen, you can get there by clicking the “Manage Subscriptions” link at the bottom of the feed list, or by clicking on settings at the top right and then moving to the subscriptions tab.

From the subscriptions tab you can rename the feed if required, then you will want to use the Change Folders drop down menu to assign the feed to a category.

Now that you have grouped your feeds together you will need to click on the Tags tab. This screen will show you the groups you have created, we will want to make the group publically shared so that our website can access it.

Once you have shared the group, return to the main page, find the group on the left hand menu and click to select it. Once you have the group selected, the viewer will show you the posts from all feeds in that group and the page will have a link to the RSS feed for hat shared group. If you are using Internet Explorer you should be able to select the shared feed from a orange icon at the end of the address bar.

Your shared feed should be something like the following:

http://www.google.com/reader/atom/user%2F00000000000000000000%2Flabel%2FF1?r=n

You should see in the above URL that %2F is an encoded forward slash and the random numbers are how your Google account is identified (represented by zeros in the example above). Also the parameter on the end is not required, however we can swap it for the parameter n that will control how many items are returned.

In order to use this information on our website we want it in a usable form, luckily using Google’s JavaScript interface we can get that simply by changing the URL format to the following:

http://www.google.com/reader/public/javascript/user/00000000000000000000/label/F1?n=5

Notice here how we have replaced the start of the URL and the %2F but kept the end of it. We have also added the n parameter on the end so that only 5 items are returned in the feed.

Put this in your browser and TADA, it should return a nice big JSON (JavaScript Object Notation) data structure that we can use on our site.

BUT how do we use that?

Don’t worry, JSON can be used by almost any language with a simple conversion, take a look at http://www.json.org/ for more information about the specific language you are using.

I used Perl to implement my feeds, to convert the JSON data structure to Perl you can use the CPAN JSON or JSON::PP module http://search.cpan.org/search?query=json&mode=all

And here is a real small script that shows you how to do it, I won’t explain how this simple script works unless someone really wants me to.

#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use JSON::PP;
use LWP::Simple;
{
my $q = new CGI;
my $target = q|http://www.google.com/reader/public/javascript/user/00000000000000000000/label/F1?n=5|;
my $response = get $target;
my $rss = decode_json( $response );
my $html = '';
for my $feeditem ( sort {$b->{'published'} <=> $a->{'published'}} @{$rss->{'items'}} ) {
my $pdate = $feeditem->{'published'};
my @dprts = gmtime $pdate;
$pdate = sprintf("%02d/%02d/%4d", $dprts[3],$dprts[4],$dprts[5]+1900 );
my $href = $feeditem->{’alternate’}->{’href’};
my $content = $feeditem->{’title’};
my $title = $feeditem->{’content’};
my $source = $feeditem->{’origin’}->{’title’};
$html .= qq|\n<div>|;
$html .= qq|\n<div>$pdate: <a href=”$href”>$content</a></div>|;
$html .= qq|\n<div>via. $source</div>|;
$html .= qq|\n</div>|;
$html .= qq|\n<div> </div>|;
}
print $q->header(
-charset => ‘utf-8′,
-expires => ‘-1d’
).$html;
}

UFC 83 Thoughts

PPV on Bravo, so didn’t get to see any of the undercard.

First fight was Mark Bocek Vs. Mac Danzig

Danzig didn’t come across well on the Ultimate Fighter, acting like a bit of a jerk and a bully, but he had a good showing in this fight. Bocek was no push over and it was an exciting watch, although I was frustrated that Danzig could not seem to finish the fight by strikes, even from the mount position.

Next up was Charles McCarthy Vs. Michael Bisping

Bisping was look lean but after his recent fights I was already to direct a shed load of hate at him. But then seeing McCarthy’s attitude, especially after taking the first few shots, the brutal knees to the forearms that delivered the ending were very satisfying. Charles McCarthy should go away and not come back, and Bisping may just have earned back some lost respect.

Nate Quarry Vs. Kalib Starnes

Wow, Nate Quarry looked good. No idea what Starnes was even doing in the cage, he definitely was not there to fight, and the bare faced cheek of the guy to give Quarry the finger for venting a little frustration (and then calling out his corner man after the fight) in the final round (which we were all feeling), unbelievable! I desperately wanted to see Nate kick his teeth in, but alas a decision, and a massive one at that with one judge giving Starnes just 24 points.

Looking forward to seeing Nate Quarry in action again

Travis Lutter Vs. Rich Franklin

Another dose of sweet justice delivered by a fist in this fight. Lutter said some un-classy things in the pre-fight interview, calling Franklin a liar regarding an injury. This from a man who couldn’t make weight? Franklin got a little complacent in the fight and nearly got caught, but then turned it up for the next round and smashed Lutter, I very much enjoyed the fact Rich didn’t rush to the win, so we got to see Travis take a few more shots to the face. Brilliant fight, and Franklin looks to be back to his best, should get an interesting fight next.

Finally, Matt Serra Vs. Georges St-Pierre

Not much to be said about this one, slightly disappointing that Serra couldn’t get in more offense but at least he fared better than Hughes. I think deep down everyone (event the most zealous Serra fans) probably knew St-Pierre would get the best in this fight, but it was entertaining while it lasted.

Now that is over with, let’s hope we get to see Serra take on Hughes, Serra for the win!

Well overall, one of the better PPV from UFC in recent memory.

Uncensored! Fucking Awesome

So this is my brand new blog, but this one is different. Unlike previous blogs I’ve setup, out of curiosity or wanting to be in the trend, this one might actually get more than the christening post. The reason being? Well this blog is totally uncensored, so I am led to believe.

Browsing random RSS feeds with Google reader, I came across this post: http://torrentfreak.com/baywords-pirate-bay-blog-080416/

 

So, don’t know what I am going to post up in future, probably just try to keep to at least one post per week of whatever random stuff I find interesting around the net and life in general.

Note to self: some upcoming events of interest that might provide some good blogging:

  • UFC  83, really hope Serra pulls the upset
  • Monster Jam, a monster truck event in June at Cardiff Millennium Stadium, quite fancy going to that
  • Battlefield Heroes, looks like it’s shaping up to be one of the best free games around
  • New PS3 Store, I updated my PS3 today and checked out the new store, looks alright I spose