From: Mark L. <no...@nu...> - 2010-06-10 16:47:41
|
On Thu Jun 10, 2010 at 06:09:27PM +0200, Mark Lawrence wrote: > > The attached Perl script (abook2remind.pl) extracts the 'anniversary' It would be nice if the mailing list software didn't fudge around with line spacing in attachments. Here is an inline copy: #!/usr/bin/perl # # abook2remind.pl - convert "abook" anniversaries to "remind" events # # Copyright 2010 Mark Lawrence <no...@nu...> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or (at # your option) any later version. # use strict; use warnings; use File::Spec; use File::HomeDir; ( my $me = $0 ) =~ s/.*\\//; sub usage { print STDERR "usage: $me [ <input> [ <output> ] ]"; exit 1; } my @months = (qw/ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec /); my $input = $ARGV[0] || File::Spec->catfile( File::HomeDir->my_home, '.abook', 'addressbook' ); my $output = $ARGV[1] || File::Spec->catfile( File::HomeDir->my_home, '.abook', 'birthdays' ); open(IN, '<', $input) || die "open $input: $!"; my $temp_out = $output . '.new'; open(OUT, '>', $temp_out) || die "open $output: $!"; print OUT "# Generated ". scalar localtime(time) ."\n\n"; print OUT "FSET since(x) ord(year(trigdate())-x)\n"; print OUT "FSET age(x) year(trigdate())-x\n\n"; my $name; my $date; while ( my $line = <IN> ) { chomp $line; if ( $line =~ /^name=(.*)/ ) { $name = $1; } elsif ( $line =~ /^anniversary=(\d\d\d\d)-(\d\d)-(\d\d)$/ ) { my ( $year, $month, $day ) = ( $1, $months[$2-1], $3 ); print OUT "REM $day $month MSG Birthday: $name ([age($year)])\n" } } close(IN); close(OUT); rename( $temp_out, $output ) || die "rename: $!"; exit 0; __END__ Regards, Mark. -- Mark Lawrence |