Selling cookie info to third-parties is a classic example of you can make money without doing evil.
RSS

Comments RSS feed

2005/04/25 filed under /nanoblogger

Probably only interesting for BOK and myself: comments.rss

This feed will be updated every hour (poor cron) and will display the latest comments found here.

I've hacked it up in Perl and yeah, it probably only works on my system (I've tried to use the blog.conf as much as possible), but here's the source anyways:

  #!/usr/bin/perl

  use strict;
  use XML::RSS::SimpleGen;

  my %config = ReadConfig();

  my $commenturl = "http://menno.b10m.net/cgi-bin/cgicomment.pl?article=archives";
  my $cgicomments = "$config{blog_dir}/cgicomment/comments";
  
  rss_new($config{blog_url}, "$config{blog_title}'s Comments", 
          "Comments for $config{blog_title}" );
  rss_language('en');
  rss_hourly();
    
  open COMMENTS, "<", "$cgicomments/comments.db" 
     or die "Can't open $cgicomments/comments.db: $!";
  my @comments = reverse (<COMMENTS>);
  close COMMENTS;
  
  my ($title, $article);
  for(my $i=0; $i <= 10; $i++) {
     my ($art_id, $com_id) = split(/\|/, $comments[$i]);
     open ART, "<", "$cgicomments/articles.db" 
        or die "Can't open $cgicomments/articles.db: $!";
     while(<ART>) {
        $article = $1 if($_ =~ m/^$art_id\|archives\/(.*).html$/);
        open FH, "<", "$config{blog_dir}/data/$article.txt";
        while(<FH>) {
           if($_ =~ m/^TITLE: (.*)$/) {
               $title = $1;
               last;
           }
        }
     }
     close ART;
  
     my $comment;
     chomp($com_id);
     open WHO, "<", "$cgicomments/$com_id.inf" 
        or die "Can't open INF file ($com_id.inf): $!";
     my $who = (split(/\|/, <WHO>))[0];
     close WHO;
  
     open COMMENT, "<", "$cgicomments/$com_id.msg" 
        or die "Can't open comment ($com_id.msg): $!";
     map { $comment .= $_ } (<COMMENT>);
     close COMMENT;
     rss_item("$commenturl/$article.html#comments&from_rss=$com_id", $title, 
              "\"$who\" wisely pointed out: $comment");
  }
  
  rss_save( '/home/menno/html/blog/comments.rss' ) if(rss_item_count());
  
  ################################################################################
  sub ReadConfig {
     my %config;
     open CF, "<", "$ENV{HOME}/.nb.conf" or die "Can't open $ENV{HOME}/.nb.conf";
     $config{blog_dir} = $1 if(<CF> =~ /BLOG_DIR="([^"]+)"/);
     $config{blog_dir} =~ s/\$HOME/$ENV{HOME}/;
     close CF;
  
     open BC, "<", "$config{blog_dir}/blog.conf" 
        or die "Can't open $config{blog_dir}/blog.conf: $!";
     while(<BC>) {
        next if(/^\s*#/);
        $config{lc($1)} = $2 if(/^([^=]+)="(.*)"$/);
     }
     close BC;
  
     return %config;
  }
Posted by: B10m | permanent link | comments (0)
Comments are closed for this story.
Trackbacks are closed for this story.
return-member