[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [syndication] RSS feeds for bookmarks
You could use XSLT if the !#$@# bookmark file was proper XML (even
XHTML...)
I guess you could run it through tidy -asxml to do this...
On Sun, Nov 25, 2001 at 10:00:10PM +0000, Libby Miller wrote:
>
>
> On Sun, 25 Nov 2001, Mark Nottingham wrote:
>
> >
> > Interesting. I'm using RSS because I wanted to expose "recently added
> > bookmarks", so that someone could subscribe and watch for new things
> > in my bookmarks.
>
> nice one - I've been thinking about something similar - little perl
> script below, which turns bookmarks files into RSS 1.0. It doesn't pull
> out the top 10 by date, but could do so easily (my perl's not up to
> much).
>
> cheers
>
> libby
>
> #!/usr/bin/perl
>
> use Netscape::Bookmarks;
> use Netscape::Bookmarks::Link;
> use Netscape::Bookmarks::Category;
>
>
> my $bookmarks_file= $ARGV[0];
> my $nick= $ARGV[1];
>
>
> my $bookmarks = Netscape::Bookmarks->new( $bookmarks_file );
>
> print toRSS($bookmarks);
>
>
> sub toRSS
> {
> my $self = shift;
>
> my $title = $self->title;
>
> my $str = "<?xml version=\"1.0\" encoding=\"iso8859-1\"?>\n";
> $str .="<rdf:RDF xmlns=\"http://purl.org/rss/1.0/\"\n";
> $str .=" xmlns:foaf=\"http://xmlns.com/foaf/0.1/\"\n";
> $str .=" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n" ;
> $str .=" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
> $str .=" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" >\n";
>
> $str .="<channel rdf:about=\"http://intranet.ilrt.bris.ac.uk/files/private/temp/bookmarks/thirdstage/$bookmarks_file\">\n<link>http://intranet.ilrt.bris.ac.uk/files/private/temp/bookmarks/thirdstage/$bookmarks_file</link>\n";
> $str .="<title>$title</title>\n<description>$title</description>\n<items>\n<rdf:Seq>";
>
>
> foreach my $ref ( @{$self->elements} )
> {
> $str .= as_list($self,\$ref, 1);
> }
>
> $str .= "</rdf:Seq>\n</items>\n</channel>\n\n";
>
> foreach my $ref ( @{$self->elements} )
> {
> $str .= as_items($self,\$ref, 1);
> }
>
> $str .= "</rdf:RDF>";
>
> $str=~ s/&/&/g;
> # $str=~ s/&/%26/g;
> return $str;
> }
>
>
>
> sub as_list
> {
> my $self = shift;
> my $obj = shift;
> my $level = shift;
>
>
> my $str;
>
> if( ref $$obj eq 'Netscape::Bookmarks::Category' )
> {
> foreach my $ref ( @{($$obj)->elements} )
>
> {
> $str .= as_list($self, \$ref, $level);
> }
> }
>
> elsif( ref $$obj eq 'Netscape::Bookmarks::Link' )
> {
> my $title = ($$obj)->title;
> my $url = ($$obj)->href;
>
> $str .= "<rdf:li rdf:resource=\"". $url."\"/>\n";
> }
>
> return $str;
>
> }
>
>
> sub as_items
> {
> my $self = shift;
> my $obj = shift;
> my $level = shift;
> my $cat = shift;
>
>
> my $str;
>
> if( ref $$obj eq 'Netscape::Bookmarks::Category' )
> {
> foreach my $ref ( @{($$obj)->elements} )
> {
> my $title = ($$obj)->title;
> $str .= as_items($self, \$ref, $level, $title);
> }
> }
>
> elsif( ref $$obj eq 'Netscape::Bookmarks::Link' )
> {
> my $title = ($$obj)->title;
> my $url = ($$obj)->href;
> my $desc = ($$obj)->description;
> my $date = ($$obj)->add_date;
>
> $str .= "<item rdf:about=\"".$url."\">\n<link>$url</link>\n<title>$title</title>\n";
> if($desc ne ""){
> $str .= "<description>$desc</description>";
> }
>
> if($cat ne ""){
> $str .= "\n<dc:subject>".$cat."</dc:subject>";
> }
>
>
> if($date ne ""){
> my @time=gmtime($date);
> my $mon=@time[4]+1;
> my $day=@time[3];
> my $year=@time[5]+1900;
>
> my $dd= $year."-".$mon."-".$day;
>
> $str .= "\n<dc:date>$dd</dc:date>";
> }
>
>
>
> $str .= "\n<dc:creator>\n<foaf:Person>\n<foaf:mbox rdf:resource=\"".$nick."\" />\n</foaf:Person>\n</dc:creator>\n</item>\n\n";
> }
>
> return $str;
>
> }
>
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
--
Mark Nottingham
http://www.mnot.net/