[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] List of dates from evolutions calendar



Joerg Johannes wrote:

Hi everybody

Does anybody use the calendar function of evolution? I do, and I like
it, but I'm missing one feature. I'd like to let the program make a list
of dates such as:

2004/06/05	10:30	Choir rehearsal in Neustadt
2004/07/02	20:00	Heather Nova Concert in Freiburg
2004/07/08	19:00	Jan Garbarek Concert in Freiburg
...

I poked around in the menus, but did not find such a list-making
function. Maybe I can somehow grep dates out and sort/format them with
some perl hack... I'm just not skilled enough to get that done by myself
:(. Any ideas or pointers would be great.
I use Korganizer which stores in .ics files. I wrote this Perl script to do exactly that for .ics files. Since ics files are not in date order it sorts the data into date order. Maybe it will help.

usage:  portcal.pl <file.ics>

Paul Scott


#! /usr/bin/perl

use strict;

my $in;
my @event;

#if( $ARGV[0] ) {
#    print "$ARGV[0]\n";
#    if( $ARGV[1] ) {
#    $in = $ARGV[1];
#    }
#}

$in = $ARGV[0];

my $isEvent = 0;
my $eventNumber = 0;
my $i;
my $j;
my $j2;
my $tmp;
my @event;
my $zone = 7;

sub HourFix {
   my ( $hour, $zone ) = @_;
   $hour -= $zone;
   if( $hour < 0 ) {
   $hour += 24;
   }
   return $hour;
}

open( IN, $in ) or die "Can't open $in";
while( <IN> ) {
   if( /BEGIN:VEVENT/ ) {
   $isEvent = 1;
   ++$eventNumber;
   next;
   }
   if( $isEvent ) {
   if( /END:VEVENT/ ) {
       $isEvent = 0;
       next;
   }
     SWITCH: {
     if( /SUMMARY:(.*)/ ) { $event[$eventNumber]{summary} = $1; next; }
     if( /DTSTART:(.*)/ ) { $event[$eventNumber]{start} = $1; next; }
     if( /DTEND:(.*)/ )   { $event[$eventNumber]{end} = $1; next; }
     if( /LOCATION:(.*)/ ) { $event[$eventNumber]{location} = $1; next; }
     }
   }
}

for $i ( 0 .. $#event ) {
   $j2 = $#event - 1;
   for $j ( 0 .. $j2 ) {
   if( $event[$j+1]{start} < $event[$j]{start} ) {
       $tmp = @event[$j];
       @event[$j] = @event[$j+1];
       @event[$j+1] = $tmp;
   }
   }
}

print "\nNumber of events: $#event\n";
for my $row ( @event ) {
   my $xx = $row->{start};
   my $year  = substr( $xx, 0, 4 );
   my $month = substr( $xx, 4, 2 );
   my $day   = substr( $xx, 6, 2 );
   my $hour = substr( $xx, 9, 2 );
   my $startHour = HourFix( $hour, $zone );
   my $startAMPM = "am";
   if( $startHour > 12 ) {
   $startHour -= 12;
   $startAMPM = "pm";
   }
   my $startMinute = substr( $xx, 11, 2 );
   $hour = substr( $row->{end}, 9, 2 );
   my $endHour   = HourFix( $hour , $zone );
   my $endAMPM = "am";
   if( $endHour > 12 ) {
   $endHour -= 12;
   $endAMPM = "pm";
   }
   my $endMinute = substr( $row->{end}, 11, 2 );
   print "$month/$day/$year - $startHour:$startMinute$startAMPM -";
   print "$endHour:$endMinute$endAMPM - ";
   print "$row->{summary}";
   my $location = $row->{location};
   if( $location ) {
   print " - $location";
   }
   print "\n";
}





Reply to: