summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/events2md.pl25
1 files changed, 20 insertions, 5 deletions
diff --git a/bin/events2md.pl b/bin/events2md.pl
index 7fd8a5e..9423133 100755
--- a/bin/events2md.pl
+++ b/bin/events2md.pl
@@ -19,6 +19,7 @@ use Log::Any::Adapter;
use URI;
use IO::Prompter;
use Cal::DAV;
+use Data::ICal;
use iCal::Parser;
use List::Util qw(first);
use List::MoreUtils qw(nsort_by sort_by);
@@ -51,7 +52,7 @@ $base_uri = URI->new($BASE_URI)
$base_uri
or $log->fatal('required base URI not provided') && exit 2;
$base_uri->scheme
- or $log->fatal('bad base URI: must be an internet URI') && exit 2;
+ or $base_uri->scheme('file');
if ( $base_uri->scheme eq 'http' or $base_uri->scheme eq 'https' ) {
$log->infof( 'will use base URI %s', $base_uri );
$calendar_uri = URI->new( $CALENDAR_URI || $base_uri );
@@ -81,8 +82,8 @@ if ( $base_uri->scheme eq 'http' or $base_uri->scheme eq 'https' ) {
}
$log->debugf( 'resolved credentials for user %s', $user );
- # fetch and parse calendar data
- $log->debug('fetch and parse calendar data...');
+ # fetch and parse CalDAV calendar data
+ $log->debug('fetch and parse CalDAV calendar data...');
$calendar = Cal::DAV->new(
user => $user,
pass => $pass,
@@ -91,8 +92,22 @@ if ( $base_uri->scheme eq 'http' or $base_uri->scheme eq 'https' ) {
$calendar->get($calendar_uri)
if $calendar_uri;
}
-else {
- $log->fatal('bad base URI: must be an internet URI') && exit 2;
+elsif ( $base_uri->scheme eq 'file' ) {
+ defined $base_uri->file
+ or $log->fatal('bad base URI: cannot open file') && exit 2;
+ $log->infof( 'will use base URI %s', $base_uri );
+
+ # parse local calendar data
+ $log->debug('parse local calendar data...');
+ my $path = path( $base_uri->file );
+ if ( $path->is_file ) {
+ $calendar = Data::ICal->new( data => $path->slurp_raw );
+ }
+ else {
+ my $data;
+ $path->visit( sub { $data .= $_->slurp_raw if $_->is_file } );
+ $calendar = Data::ICal->new( data => $data );
+ }
}
if ( $log->is_trace ) {
use DDP;