Long time ago i asked if someone has a bbdb2html.  No response, and
yesterday i googled without success.  So i have to write it on my
own. 

bbdb2txt is a very small perlscript.  Good for own hacks.

bbdb2html is a searchable perl CGI Script.  It runs tainted (-T), so
perhaps it is hopefully not that insecure.  I suggest a static HTML
copy for big databases/slow machines. On my P166 with 800 Records it
takes 5 seconds. It uses cookies for preferences, but you could also
just bookmark the resulting URL.

Both Scripts needs perl-lisp for LISP::READER, available at your CPAN
Mirror.  Of course, both need to adjust the path to your ~/.bbdb.

I'd love to see your Comments and Bugfixes.


Aldo

#!/usr/bin/perl
#
# Aldo Valente, Fri Feb 14 15:26:36 CET 2003
# 
# bbdb2txt
# 
#
# $Id$
#
# $Log$

use Lisp::Reader ;
use Lisp::Printer;

while (<>) {

#  print;
  next unless /^\[/;  # No Nonamers
 
 @bbdb = @{${&Lisp::Reader::lisp_read($_)}[0]};
 next  unless @bbdb[0..1];
  print "-------------------------------------------------\n";
#       Name         Nname        aka         title
  print "$bbdb[0] $bbdb[1] $bbdb[2][0] $bbdb[3]\n";
 
  # Array of Array of Location/Number
  for $i ( @{ @bbdb[4]||break} ) {
    print " $i->[0]:\t  $i->[1]  \n";
  } 

  # Array of Array of something of Addresses
  for $i ( @{ @bbdb[5]||break} ) {
    print " $i->[0] \n";
    # Street
    print "  @{$i->[1]}\n" ;
    # Town, State, ZIP, unknown
    print "  $i->[2] $i->[3] $i->[4] $i->[5]\n";
  }

  if ( @{ @bbdb[6]} ) {
    for $i ( @{ @bbdb[6]} ) {
      print "E-Mail: $i\n";
    }
  }
  # Notes
  for $i ( @{ @bbdb[7]||break} ) {
    print "$i->[0]{name}: $i->[1]\n";
  }
}
#!/usr/bin/perl -T
#
# Aldo Valente, Fri Feb 14 15:26:36 CET 2003
# 
# bbdb2html
# 
#
# $Id: bbdb2html,v 1.3 2003/02/16 17:25:09 aldo Exp $
#
# $Log: bbdb2html,v $
# Revision 1.3  2003/02/16 17:25:09  aldo
# *** empty log message ***
#
# Revision 1.2  2003/02/16 00:16:29  aldo
# not much
#
# Revision 1.1  2003/02/16 00:15:53  aldo
# Initial revision
#

use Lisp::Reader ;
use Lisp::Printer;
use CGI qw/:standard/;

######  YOUR PATH HERE ! ######
$PATHTOBBDB='/home/aldo/.bbdb';
###############################

undef $ENV{PATH} ;              # because -T switch
$q = new CGI;

%labels =( 'nil' => 'Discard no Records' ,
             'p'   => 'Discard Records without Phonenumbers' ,
             'e'   => 'Discard Records without E-Mail' ,
             'pe'  => 'Discard Records without E-Mail or Phonenumbers' );

%pref = $q->cookie('pref') unless (param('zap'));
# useless Defaults
$pref{p} = 'p'              unless $pref{p};
$pref{a} = 'Show Addresses' unless $pref{a};
$pref{m} = 'Show E-Mail'    unless $pref{m};
$pref{n} = 'Show Notes'     unless $pref{n};
$pref{t} = 'Show Phone'     unless $pref{t};

# URL overrides, else cookie wins
$pref{a} = $q->param('a') || $pref{a};
$pref{p} = $q->param('p') || $pref{p};
$pref{m} = $q->param('m') || $pref{m};
$pref{n} = $q->param('n') || $pref{n};
$pref{t} = $q->param('t') || $pref{t};

for $abc ( A .. Z) {
  $letters .= "<a href=\"#$abc\">$abc</a>   ";
}
$letters .= "<a href=\"#top\">Top/Search</a>  ";

open BBDB, $PATHTOBBDB or die "open bbdb";

while (<BBDB>) {
  push @BBDB, $_;
}

@BBDB = grep  /^\[/, @BBDB;


$the_cookie = $q->cookie(-name=>'pref',
                         -value=>\%pref,
                         -path=>$q->url(-absolute=>1),
                         -expires=>'+300d');

if (param('zap')) {
  $the_cookie = $q->cookie(-name=>'pref',
                           # must not undef'ed
                           -value=>{},
                           -path=>$q->url(-absolute=>1),
                           # negative expires wont work
                           -expires=>'+300d');
}

print $q->header(-expires=>'-1d',
                 -cookie=>$the_cookie
                );

print start_html(-title=>'bbdb2html',
                 -author=>'[EMAIL PROTECTED]',
                 -meta=>{'keywords'=>'bbdb html',
                         'copyright'=>'GPL'},
                ),
  "<a name=\"top\"></a>",
  start_form(-method=>"Get"),
  textfield('name'),
  submit(-name=>'Search'),
  $q->popup_menu(-name=>'p',
                 -values=>['nil', 'p', 'e', 'pe'],
                 -defaults=>$pref{p},
                 -labels=> \%labels,
                ),
  "<br>",
  $q->popup_menu(-name=>'a',
                 -values=>[ 'Show Addresses' , 'Suppress Addresses'],
                 -defaults=>$pref{a},
                ),
  $q->popup_menu(-name=>'m',
                 -values=>[ 'Show E-Mail' , 'Suppress E-Mail'],
                 -defaults=>$pref{m},
                ),
  $q->popup_menu(-name=>'n',
                 -values=>[ 'Show Notes' , 'Suppress Notes'],
                 -defaults=>$pref{n},
                ),
  $q->popup_menu(-name=>'t',
                 -values=>[ 'Show Phone' , 'Suppress Phone'],
                 -defaults=>$pref{t},
                ),
  "<br><small><i>Activate cookies, or at least bookmark your preferences.</i>  ",
  "<a href=\"", $q->url , "?zap=on\">Reset Prefs</a></small>\n",
  end_form;

if (param('name')) {
  $name = $q->param('name');
  $name =~ s/[^0-9a-zA-Z\@]//g;
  @BBDB = grep /$name/i, @BBDB;
  print "<b>Searchstring:  $name</b><br>";

}

$ab=undef;
foreach (@BBDB) {
  next unless $_;
  @bbdb = @{${&Lisp::Reader::lisp_read($_)}[0]};
  # Nophones
  if ( $pref{p} =~ 'p') {
    unless ( @bbdb[4]) {
      # print STDERR "$_ is gone wg Nophones\n";
      $_ = undef;
      next;
    }
  }
  if ( $pref{p} =~ 'e') {
    unless ( @bbdb[6]) {
      # print STDERR "$_ is gone wg Nomail\n";
      $_ = undef;
      next;
    }
  }
  # Nonamers.  Are you there?
  unless ($bbdb[0..3]) {
    # print STDERR "$_ is gone wg Noname\n";
    $_ = undef;
    next;
  }
  #  New Letter?
  if ( uc( substr ($bbdb[1],0,1)) gt $ab ) {
    $ab = uc( substr ($bbdb[1],0,1)) ;
    print "<hr> $letters <h1><a name=\"$ab\">\nBuchstabe $ab </a></h1>";
  }
  #       Name         Nname        aka         title
  print "<p><big><u>$bbdb[0] $bbdb[1]</u></big>&nbsp;&nbsp;&nbsp; 
         <i>$bbdb[2][0] $bbdb[3]</i><br>\n";

  print "<table border=\"0\" width=\"80%\"><tr><td width=\"40%\" valign=\"top\">";
  # Array of Array of Location/Number
  if ($pref{t} eq 'Show Phone') {
    for $i ( @{ @bbdb[4]||break} ) {
      print " $i->[0]:\t <b> $i->[1] </b> <br>\n";
    } 
  }
    print "</td><td width=\"60%\" valign=\"top\" align=\"left\">";

  # Mail
  if ($pref{m} eq 'Show E-Mail') {
    if ( @{ @bbdb[6]} ) {
      for $i ( @{ @bbdb[6]} ) {
        print "<a href=\"mailto:$i\";>$i</a><br>\n";
      }
    }
  }
  print "</td></tr><tr><td width=\"40%\" valign=\"middle\">";

  # Notes
  if ($pref{n} eq 'Show Notes') {
    for $i ( @{ @bbdb[7]||break} ) {
      print "<small>$i->[0]{name}: $i->[1]<br></small>\n";
    }
  }
  print "</td><td width=\"60%\" valign=\"top\" align=\"left\">";
 

  if ($pref{a} eq 'Show Addresses') {
    print "<dl>";
    # Array of Array of something of Addresses
    for $i ( @{ @bbdb[5]||break} ) {
      print " <dt><b>$i->[0] </b></dt><br>\n";
      # Street
      print " <dd> @{$i->[1]}<br>\n" ;
      # 2 Town, 3 State, 4 ZIP, 5 unknown
      print "  $i->[3] $i->[4] $i->[2] $i->[5]</dd><br>\n";
    }
    print "</dl>";
  }
  print "</td></tr></table>";
  $printed++;
}

print "<hr><small> processed ",  $#BBDB+1, " Records. " , 
  $printed  || "No" , " Addresses shown.\n<br> ",
  "Source can be found at <a href=\"http://valente.de/aldo/bbbd/\";>
 http://valente.de/aldo/bbbd/</a>. <br> Generated on ";
print `/bin/date`;
print "</small></body></html>\n";

Reply via email to