[Remind-Fans] never mind help calculating event dates

Justin Alcorn justin at jalcorn.net
Mon Dec 3 18:32:44 EST 2012


Oh, sorry.  THis is the guts of cal_futureonly.pl.  It drops everything
more than a month old, unless it has repeating entries that are still valid.

use strict;
use Data::ICal;
use Date::ICal;
use Data::ICal::Entry;
use DateTime;
use Getopt::Long 2.24 qw':config auto_help';
use Pod::Usage;
use Data::Dumper;
use vars '$VERSION';
$VERSION = "0.5.2";

# Declare how many days in advance to remind
my $DEFAULT_LEAD_TIME = 3;
my $PROCESS_TODOS     = 1;
my $HEADING                       = "";
my $help;
my $man;
my $file;

my $label = 'Calendar';
GetOptions (
        "label=s"     => \$label,
        "lead-time=i" => \$DEFAULT_LEAD_TIME,
        "todos!"          => \$PROCESS_TODOS,
        "heading=s"       => \$HEADING,
        "help|?"          => \$help,
        "man"             => \$man,
        "file=s"      => \$file
);
pod2usage(1) if $help;
pod2usage(1) if (! $file);
pod2usage(-verbose => 2) if $man;

my $month =
['None','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

my @calendars;
my $in;

my $limit = Date::ICal->new();
$limit->add(month => -1);
print STDERR "Archiving Events before: ",$limit->ical,"\n" if $debug;
my $input = "full/".$file;
print STDERR "Parsing $input\n" if $debug;
my $cal = Data::ICal->new(filename => $input);
if (! $cal) {
        die $cal->error_message;
}
#my $archive = Data::ICal->new(filename => 'archive.ics');
print "Output = $file\n" if $debug;
my $new = Data::ICal->new();
if (! $new) {
        die $new->error_message;
}

##############################################################
#
# Subroutines
#
#############################################################
#


#######################################################################
#
#  Main Program
#
######################################################################
my $new_entries = $new->entries();
@$new_entries = ();
my $cal_entries = $cal->entries();
foreach my $index (0 .. $#$cal_entries) {
        my $entry = $$cal_entries[$index];
        print STDERR $entry->ical_entry_type(),"\n" if $debug;
        my $enddate;
        if ($entry->ical_entry_type eq "VEVENT") {
                my $summ = $entry->property("SUMMARY");
                print STDERR $summ->[0]->as_string if $summ->[0] and $debug;
                my $dtend = $entry->property("DTEND");
                my $rrule = $entry->property("RRULE");
                if ($rrule->[0]) {
                        my $until;
                        my $value = $rrule->[0]->value;
                        if ($value =~ /UNTIL=/) {
                                my @vals = split(";",$value);
                                foreach my $v (@vals) {
                                        my ($v1,$v2) = split("=",$v);
                                        if ($v1 eq "UNTIL") {
                                                $enddate =
Date::ICal->new(ical => $v2);
                                                $until = $v2;
                                        }
                                }
                                print STDERR "Repeating Until:
",$until,"\n" if $debug;
                        } else {
                                print STDERR "Repeating: ",$value,"\n" if
$debug;
                                $enddate = Date::ICal->new();
                        }
                } elsif ($dtend->[0]) {
                        print STDERR $dtend->[0]->value,"\n" if $debug;
                        $enddate = Date::ICal->new(ical =>
$dtend->[0]->value);
                } else {
                        print STDERR "No Ending Date\n" if $debug;
                        $enddate = Date::ICal->new();
                }
                if ($limit->compare($enddate) > 0) {
                        print STDERR "Archive this event\n" if $debug;
                        #$archive->add_entry($entry);
                } else {
                        $new->add_entry($entry);
                }
        } else {
                $new->add_entry($entry);
        }
}

#open(ARCHIVE, ">archive.ics");
#print ARCHIVE $archive->as_string;
#close ARCHIVE;

open(NEW, ">$file");
print NEW $new->as_string;
close NEW;
exit 0;
#:vim set ft=perl ts=4 sts=4 expandtab :


-- 
Justin B. Alcorn
PGP Fingerprint A36D D691 C5B0 BE15 5A2A AF49 AA1C 372C


On Mon, Dec 3, 2012 at 6:29 PM, Justin Alcorn <justin at jalcorn.net> wrote:

> ical2rem.pl
>
> That's why I wrote it.
>
> I have a script that runs this:
>
> wget -q -O full/justin.ics --no-check-certificate
> https://www.google.com/calendar/ical/jbalcorn\%40gmail.com/private-ec6xxxxxxxxxxxxxxxxxxxxxxx567d13/basic.ics<https://www.google.com/calendar/ical/jbalcorn%5C%40gmail.com/private-ec6xxxxxxxxxxxxxxxxxxxxxxx567d13/basic.ics>
>
> Along with every other google calendar I'm interested in, i.e.:
>
>
> wget -q -O USHolidays.ics
> http://www.mozilla.org/projects/calendar/caldata/USHolidays.ics
>
> I get rid of past events:
>
> ~/bin/cal_futureonly.pl --file=justin.ics
>
> Then I run this:
>
> 0-59/30 * * * * cat ~/calendars/*.ics | local/bin/ical2rem.pl --label
> "Online Calendar" --heading "PRIORITY 9999" --lead-time 5  > ical2rem && mv
> ical2rem .ical2rem
>
> And include .ical2rem in my .reminders file
>
>
>
> --
> Justin B. Alcorn
> PGP Fingerprint A36D D691 C5B0 BE15 5A2A AF49 AA1C 372C
>
>
> On Mon, Dec 3, 2012 at 6:22 PM, hymie! <hymie at lactose.homelinux.net>wrote:
>
>>
>> Justin Alcorn writes:
>> >ical2rem.pl will take the ical files created by apple calendars and
>> create
>> >remind files,
>>
>> Sorry.  I mis-spoke.
>>
>> Remind is ***awesome*** .  I just wish I could sync it with Google.
>>
>> --hymie!    http://lactose.homelinux.net/~hymie
>> hymie at lactose.homelinux.net
>>
>> -------------------------------------------------------------------------------
>> _______________________________________________
>> Remind-fans mailing list
>> Remind-fans at lists.roaringpenguin.com
>> http://lists.roaringpenguin.com/cgi-bin/mailman/listinfo/remind-fans
>> Remind is at http://www.roaringpenguin.com/products/remind
>>
>
>


More information about the Remind-fans mailing list