Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Using Perl to add entries in iCal Calendar

by hoschi (Initiate)
on Apr 30, 2014 at 18:45 UTC ( #1084541=perlquestion: print w/ replies, xml ) Need Help??
hoschi has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

just registered to ask this question as I feel lost. I'm neither a programmer nor do I have the broad wisdom I'm searching for here.

As a small background:

We have a shift rooster whichs is changing quite often and is managed in an xlsx sheet. Now I figured out how to get all the data out of that Excel sheet and stored it in a hash of hashes.

As I thought it would be a good idea to have me and my colleagues sync their calendars on their phones or pads with a caldav server I am looking for a way how to push the gathered data into that calendar. I installed a Baikal server on one of my machines here which is already setup.

First thing im not aware of - what modules to use. I found http:dav, Data:iCal, Cal:DAV but none of them (or their description in cpan.org) shed a light on me how to use them. It seems I am even a lil too dumb to google it properly, so I hope for the wisdom of the perl monks.

What I have so far is just a simple:

my $user = "test"; my $pass = "test"; my $url = "http://baikal.local/cal.php/principals/test/testshift"; #my $url = "http://baikal.local/cal.php"; my $cal = Cal::DAV->new( user => $user, pass => $pass, url => $url); my $dav = $cal->dav; print Dumper($cal); print Dumper($dav);

which finally gives me only

$VAR1 = bless( { 'url' => 'http://baikal.local/cal.php/principals/test +/testshift', '_dav' => bless( { '_lockedresourcelist' => bless( { +'_resources' => undef }, + 'HTTP::DAV::ResourceList' ), '_comms' => bless( { '_headers' => + bless( {}, 'HTTP::DAV::Headers' ), '_user_agent' + => bless( { + 'max_redirect' => 7, + 'protocols_forbidden' => undef, + 'show_progress' => undef, + 'handlers' => { + 'response_header' => bless( [ + { + 'owner' +=> 'LWP::UserAgent::parse_head', + 'callbac +k' => sub { "DUMMY" }, + 'm_media +_type' => 'html', + 'line' = +> '/usr/share/perl5/LWP/UserAgent.pm:612' + } + ], 'HTTP::Co +nfig' ) + }, + 'no_proxy' => [], + 'protocols_allowed' => undef, + 'local_address' => undef, + 'use_eval' => 1, + 'requests_redirectable' => [ + 'GET', + 'HEAD' + ], + 'timeout' => 180, + 'def_headers' => bless( { + 'user-agent' => 'DAV.pm/v0.47' + }, 'HTTP::Headers' ), + 'proxy' => {}, + 'basic_authentication' => { + 'baikal.local:80' => { + + 'default' => [ + + 'test', + + 'test' + + ] + +} + }, + 'max_size' => undef + }, 'HTTP::DAV::UserAgent' ) }, 'HTTP::DAV:: +Comms' ) }, 'HTTP::DAV' ), '_auto_commit' => undef }, 'Cal::DAV' ); $VAR1 = bless( { '_lockedresourcelist' => bless( { '_resources' => und +ef }, 'HTTP::DAV::Resour +ceList' ), '_comms' => bless( { '_headers' => bless( {}, 'HTTP:: +DAV::Headers' ), '_user_agent' => bless( { 'max_r +edirect' => 7, 'proto +cols_forbidden' => undef, 'show_ +progress' => undef, 'handl +ers' => { + 'response_header' => bless( [ + { + 'owner' => 'LWP::UserAgent: +:parse_head', + 'callback' => sub { "DUMMY" + }, + 'm_media_type' => 'html', + 'line' => '/usr/share/perl5 +/LWP/UserAgent.pm:612' + } + ], 'HTTP::Config' ) + }, 'no_pr +oxy' => [], 'proto +cols_allowed' => undef, 'local +_address' => undef, 'use_e +val' => 1, 'reque +sts_redirectable' => [ + 'GET', + 'HEAD' + ], 'timeo +ut' => 180, 'def_h +eaders' => bless( { + 'user-agent' => 'DAV.pm/v0.47' + }, 'HTTP::Headers' ), 'proxy +' => {}, 'basic +_authentication' => { + 'baikal.local:80' => { + 'default' => [ + 't +est', + 't +est' + ] + } + }, 'max_s +ize' => undef }, 'HTTP +::DAV::UserAgent' ) }, 'HTTP::DAV::Comms' ) }, 'HTTP::DAV' );

On the Baikal Server the user test with password test is there and has a calendar created named testshift.

I found some sniplets in the web but none of them enabled me to understand HOW to add an entry. Most of them even only show how to write .ics files which I guess is not what io want.

Anyone ?

Thanks

Comment on Using Perl to add entries in iCal Calendar
Select or Download Code
Re: Using Perl to add entries in iCal Calendar (cpan secrets)
by Anonymous Monk on May 01, 2014 at 02:47 UTC

      Thanks for your reply.

      I played around with the sniplets I could find there but I am afraid Cal::DAV is not working for me here as
      new <args>
      Must have at least user, pass and url args where url is the url of a remote, DAV accessible .ics file.

      The Baikal server stores everything in a mysql database.
      I can connect with my iPad to the baikal server and update stuff in the 2 calendars I created there.
      I don't see a way with the modules in question to connect w/o having an ics file ?

      edit: Checking the mysql database for baikal server it shows the following in "calendarobjects" table:
      id calendardata uri calendarid lastmodified etag + size componenttype firstoccurence lastoccurence 1 [BLOB - 361Bytes] C7BA52BD-351F-4E64-8313-80C8B3E646E1.ics + 2 1398950718 022413b6addaecadea550ea8a8e45020 361 V +EVENT 1398902400 1398988800
      where calendarid 2 reflects the "testshift" calendar. It also shows an *.ics is there but this one can not be found in filesystem.
      Seems the server sends the "fake ics" to the client somehow, so maybe there is a chance for Cal::DAV .. but I'm lost again. "My" google doesnt know much about perl and baikal :-/

        I don't see a way with the modules in question to connect w/o having an ics file ?

        Um, but I thought you already connected, you gave it a url, thats all you had to do to make a connection, the url is the file, it doesn't matter how the webserver stores it on the webserver, the url is what you're getting/editing/updating...

        Try this next  print Dumper( $cal->cal ); this should fetch the calendar from the webserver, so you can read it update program for you

        #!/usr/bin/perl -- use strict; use warnings; use Data::Dumper (); Main( @ARGV ); exit( 0 ); sub Main { my $user = "test"; my $pass = "test"; my $url = "http://baikal.local/cal.php/principals/test/testshift" +; my $cal = Cal::DAV->new( user => $user, pass => $pass, url => $url, auto_commit => 0, ## don't ->save any changes, we're testing h +ere ); dd( $cal->errors ); dd( $cal->cal ); dd( $cal ); } sub dd { use Data::Dumper; print Data::Dumper->new([@_])->Sortkeys(1) ->Indent(1)->Useqq(1)->Dump . "\n"; }

        Then to add entries call add_entries ... to figure out what you need add  print Dumper( make_entry() ); to  Cal-DAV-0.6/t/01basics.t and examine the output (show me)

        Also try dave , CalDav is just WebDav which is just HTTP get :)

        dave -tmpdir ./i-baikal-tmp -debug 3 -u test -p test "http://baikal.local/cal.php/principals/test/" ... dave> get testshift dave> quit

        This should download the testshift database and save it in -tmpdir (or cwd)

Re: Using Perl to add entries in iCal Calendar
by sundialsvc4 (Abbot) on May 01, 2014 at 18:59 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1084541]
Approved by Corion
Front-paged by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2014-12-29 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls