#!/usr/bin/perl -T ################################################# # writeContext.pl : writes an XML file that # specifies a dynamic Google Custom Search # Engine that searches across sites tagged in # del.icio.us. # The Google CSE XML format is defined here # http://www.google.com/coop/docs/cse/cse_file.html # More info on the rationale for this script here # http://ancientgeeks.wordpress.com/2008/07/10/delicious-driven-google-custom-search/ # # (c) Phil Barker 2008 http://www.icbl.hw.ac.uk/~philb/ # # This software is licenced under the CC-GNU GPL # http://creativecommons.org/licenses/GPL/2.0/ ################################################# use LWP; require ("../cgi-lib.pl"); # Change this to the URL of the feed you want # # $feedurl = 'http://del.icio.us/rss/philb/gcsetest'; # Get the del.icio.us feed content into the default string $_ # my $browser = LWP::UserAgent->new; $response = $browser->get($feedurl); if ($response->is_success) { $_ = $response->content; } else { print $response->status_line, "\n"; } # Extract the links and turn them in to # @links = m/(.*)<\/link>/mig; $feedlink = shift(@links); # first link it the feedlink, not a bookmark $annotations =''; foreach $link (@links) { $link =~ s/^http:\/\///ig; # leave as this to search only bkmkd pg # $link =~ s/\/([^\/])*$/\/*/ig; # this searches from bkmrkd dir of site # # $link =~ s/\/(.)*$/\/*/ig; # this searches from root dir of site # # it's code like this that make Perl fun # $annotations = "$annotations \n" } &writeContext; sub writeContext { print qq(Content-Type: text/xml\n\n); print < Test Search Test Search $annotations STOP_PRINTING }