> Looks useful.  One thing I'd like to see is a simple way to enter the
> date.  I find myself quite often wanting to add an event that occurs
> later the same day, so a quick short-hand for entering today's date
> could be useful, perhaps.  I don't know if emacs has an interface to
> timespec stuff, like for example the one at(1) and similar commands
> use.
> 
> Just typing in 'next friday', 'tomorrow', or 'in four days' could be
> useful.
> 

I ran into a Perl script that does something like this some time ago. Written 
by Charles Mauch, it
allows you to enter reminders like "rem in 30 minutes to go to gym" to the 
reminders file from the
commandline. Of course in this example, I have aliased 'rem' to the perl script.

Attached is the script. Note: I did not write this, Charles Mauch did. I just 
can't find his
webpage now and hence have attached the script in question.

SK



      __________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com
#!/usr/bin/perl

use Date::Manip;

my $remindfile = "$ENV{'HOME'}/.reminders";

my $now = time;
my $minutes = 60; 
my $hours   = 60 * 60;
my $days    = 24 * 60 * 60;
my $weeks   = 7 * 24 * 60 * 60;
my $months  = 30 * 24 * 60 * 60;
my $years   = 365 * 24 * 60 * 60;

my $remindtype = shift( @ARGV );

if ( $remindtype eq "in" ) {

    my $number = shift( @ARGV );

    if ( $number =~ /\d+/ ) {
      my $unit = shift( @ARGV );
      
      if ( $unit eq "years" || $unit eq "year" ||$unit eq "ys" || $unit eq "y" 
) {
        
        my $destdate = $now + ( $number * $years );
        makereminder( $destdate, @ARGV );
      
      } elsif ( $unit eq "months" || $unit eq "month" || $unit eq "mos" || 
$unit eq "mo" ) {
        
        my $destdate = $now + ( $number * $months );
        makereminder( $destdate, @ARGV );

      } elsif ( $unit eq "weeks" || $unit eq "week" || $unit eq "ws" || $unit 
eq "w" ) {
      
        my $destdate = $now + ( $number * $weeks );
        makereminder( $destdate, @ARGV );
      
      } elsif ( $unit eq "days"  || $unit eq "day" || $unit eq "ds" || $unit eq 
"d" ) {
        my $destdate = $now + ( $number * $days );
        makereminder( $destdate, @ARGV );

      } elsif ( $unit eq "hours" || $unit eq "hour" || $unit eq "hs" || $unit 
eq "h" ) {

        my $destdate = $now + ( $number * $hours );
        makereminder( $destdate, @ARGV );

      } elsif ( $unit eq "mins" || $unit eq "minutes" || $unit eq "mis" || 
$unit eq "mi" ) {

        my $destdate = $now + ( $number * $minutes );
        makereminder( $destdate, @ARGV );

      } else {

        print "Dont know what \"$unit\" is.\n";

      }

    } else {

      print "Dont know when that is\n";

    }

} elsif ( $remindtype eq "at" ) {

    my $time = shift( @ARGV );
    
    # Military time given (no PM/AM)
    if ( $time =~ /^(\d+):(\d+)$/ ) {

        # Figure out when today started, then add hours and minutes given in
        # $time to the startofday.  Then pass that as the target datetime.

        my $temp = UnixDate( ParseDate( "epoch $now"), "%d %h %Y 00:00" );
        my $epoch = UnixDate( ParseDate( $temp ), "%s" );
        $epoch = $epoch + ( $1 * $hours ) + ( $2 * $minutes );
        makereminder( $epoch, @ARGV );

    # AM or PM given immediately after time.
    } elsif ( $time =~ /^(\d+):(\d+)((?:AM|PM|am|pm))$/ ) {

        my $temp = UnixDate( ParseDate( "epoch $now"), "%d %h %Y 00:00" );
        my $epoch = UnixDate( ParseDate( $temp ), "%s" );

        print "$1 $2 $3\n";

        if ( $3 eq "PM" || $3 eq "pm" ) {
            $epoch = $epoch + ( $1 * $hours ) + ( 12 * $hours ) + ( $2 * 
$minutes );
        } elsif ( $3 eq "AM" || $3 eq "pm" ) {
            $epoch = $epoch + ( $1 * $hours ) + ( $2 * $minutes );
        } else {
            die( "AM or PM!" );
        }

        makereminder( $epoch, @ARGV );

    } else {
        print "Unknown time\n";
    }

} else {

    print "Uhm, remind you when?\n";

}

sub makereminder {
    my $target = shift;
    my @message = @_;

    if ( $now > $target ) {
        print "That happens in the past\n";
        return;
    }

    my $date_string = UnixDate( ParseDate( "epoch $target"), "%d %h %Y AT 
%H:%M" );
    shift( @message ) if ( $message[0] eq "that" );
    shift( @message ) if ( $message[0] eq "to" );
    
    my $string = join(' ', @message );

    open( FH, ">>$remindfile" );
    print FH "REM $date_string MSG $string\%\n";
    close FH;

  return;

}

__END__

=head1 AUTHOR

Charles Mauch <[EMAIL PROTECTED]>

=head1 LICENSE

Copyright (c) 2007 Charles Mauch

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.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program.  If not, see L<http://www.gnu.org/licenses/>.

=head1 SEE ALSO

perl(1).

=cut

# $Id$
_______________________________________________
Remind-fans mailing list
[email protected]
http://lists.whatexit.org/mailman/listinfo/remind-fans

Reply via email to