[Remind-Fans] Remind and Exchange Web Services.

jack-remind at mudshark.org jack-remind at mudshark.org
Thu Mar 10 01:29:12 EST 2011


Hello all, 

I hacked together a simple script that pulls a data out of Exchange Web
Services, and creates remind entries over a time period. 

The attached script stores the current month's worth in a file YYMM (like
1103). I then include this file from my main calender. 

This is just one of the pieces of glue that I use to glue my shared home
calendar (distributed version control systems work quite well for sharing
calendars) with my work calendar. 

TODO:
    - the EWS perl module doesn't do timezones yet
    - EWS autodiscovery should be possible
    - a better way to do auth

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#!/usr/bin/perl -w

use strict;
use EWS::Client;
use DateTime;

my $ews = EWS::Client->new({
    server      => 'x.x.x.x', # <- get this from autodetect.xml, when that fails, from webmail properties. 
    username    => 'me',
#    use_negotiated_auth => 'True', 
    # passwd set $ENV{EWS_PASS}
});


my $entries = $ews->calendar->retrieve({
    start => DateTime->now->truncate(to => 'month'),
    end   => DateTime->now->truncate(to => 'month')->add( months => 1 ),
});

print "I retrieved ". $entries->count ." items\n";

my $filedate=DateTime->now(); 
my $filename = sprintf "%02d%02d", $filedate->strftime("%y"), $filedate->month();  # generate a filename like '1103'
open(REM, ">$filename");

while ($entries->has_next) {
  my $e = $entries->next; 
  next if ($e->IsCancelled);

  my $start = $e->Start->clone(); 
  $start->set_time_zone('America/Vancouver');

  #                "Dec 23 2011 AT 11:15'
  my $begin = sprintf "%s %2d %4d AT %02d:%02d", $start->month_abbr(), $start->day(), $start->year(), $start->hour(), $start->minute();

  #              DURATION 01:30"
  my $duration; 
  if ($e->IsAllDayEvent) { 
    $duration = "";
  } else { 
    my $end = $e->End->clone();
    $end->set_time_zone('America/Vancouver');

    my $d = $end->subtract_datetime($start); 
    $duration = sprintf "DURATION  %02d:%02d", $d->hours(), $d->minutes();
  }

  my $text;
  if ($e->has_Location) { 
    $text = sprintf "%s (%s)", $e->Subject, $e->Location; 
  } else { 
    $text = $e->Subject;
  }

  print REM "REM ", $begin, " ", $duration, " MSG %a %2 %\"", $text, "%\"%\n";
}

close(REM);
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
Jack (John) Cummings                           http://mudshark.org/
PGP fingerprint: F18B 13A3 6D06 D48A 598D  42EA 3D53 BDC8 7917 F802


More information about the Remind-fans mailing list