Calendar app - script to automate export .ics

Ask all your questions regarding OC 8.0 and 8.1 Please read the Support Forum Rules
Forum rules
The forums were migrated over to https://central.owncloud.org which is based on the forum software Discourse. The forums here is put into read-only mode starting from today.

More background information about this move and the reasoning behind it is available in this blogpost:

https://daniel.molkentin.net/2016/07/20 ... d-central/
dresda
Newbie
Posts: 4
Joined: Tue Jun 14, 2016 11:58 am
ownCloud version: 8.1.8
Webserver: Apache
Database: MySQL
OS: Linux

Calendar app - script to automate export .ics

Postby dresda » Tue Jun 14, 2016 12:26 pm

Hi to all.
My owncloud version is 8.1.8 - Linux Operating System
I need to create a cron to automate export to .ics calendar.
I have created the following .sh script but does not work.

#!/bin/sh
DATE=`date +"%Y-%W"`
# Download calendar.
wget \-O /home/dom001/Scrivania/TEST/calendar-$DATE.ics http://user:psw@server/owncloud/index.p ... hp?calid=4

where:
/home/dom001/Scrivania/TEST/ is directory where is saved .ics
user & psw are user credentials to access owncloud server

the script runs, but the file .ics created has not a ics format, it seems to be a html

I've seen there is a native script in owncloud to create a .ics but a can not understand how automate it

RealRancor
ownCloud master
Posts: 17381
Joined: Sat May 26, 2012 3:00 pm
ownCloud version: 9.0.2
Webserver: nginx
Database: MySQL
OS: Linux
PHP version: 7.0.x

Re: Calendar app - script to automate export .ics

Postby RealRancor » Tue Jun 14, 2016 2:28 pm

*gone*

dresda
Newbie
Posts: 4
Joined: Tue Jun 14, 2016 11:58 am
ownCloud version: 8.1.8
Webserver: Apache
Database: MySQL
OS: Linux

Re: Calendar app - script to automate export .ics

Postby dresda » Tue Jun 14, 2016 5:59 pm

thanks for the answers but I have already seen that link. It is about syncro between Oc and Google calendar. I need help about a script to execute the .php to export calendar to put it in a cron job.

RealRancor
ownCloud master
Posts: 17381
Joined: Sat May 26, 2012 3:00 pm
ownCloud version: 9.0.2
Webserver: nginx
Database: MySQL
OS: Linux
PHP version: 7.0.x

Re: Calendar app - script to automate export .ics

Postby RealRancor » Tue Jun 14, 2016 6:55 pm

dresda wrote:I need help about a script to execute the .php to export calendar to put it in a cron job.


Exactly this functionality is included in the linked script.
*gone*

dresda
Newbie
Posts: 4
Joined: Tue Jun 14, 2016 11:58 am
ownCloud version: 8.1.8
Webserver: Apache
Database: MySQL
OS: Linux

Re: Calendar app - script to automate export .ics

Postby dresda » Tue Jun 14, 2016 10:45 pm

I've seen but I think the process described in the link complicates things to me also because I am a newbie . Owncloud 8.1.8 has already provided a script in php exporting calendars in ics format
cattura1n.jpg
cattura1n.jpg (45.95 KiB) Viewed 422 times

the corresponding statement is the following
Cattura2n.jpg
Cattura2n.jpg (20 KiB) Viewed 422 times

so I think I have understood on various forums that using the wget command and matching the string above , I should be able to export the ics file. Obviously I made many attempts but did not succeed !
thanks again

RealRancor
ownCloud master
Posts: 17381
Joined: Sat May 26, 2012 3:00 pm
ownCloud version: 9.0.2
Webserver: nginx
Database: MySQL
OS: Linux
PHP version: 7.0.x

Re: Calendar app - script to automate export .ics

Postby RealRancor » Wed Jun 15, 2016 6:47 am

The link there is used by browsers. If you want to use wget on that you would need to somehow get a valid session by logging in before which make it a way more complex.

As already written use the script provided at that link which is exactly doing what you want without overcomplicate it.
*gone*

dresda
Newbie
Posts: 4
Joined: Tue Jun 14, 2016 11:58 am
ownCloud version: 8.1.8
Webserver: Apache
Database: MySQL
OS: Linux

SOLVED: Calendar app - script to automate export .ics

Postby dresda » Wed Jun 15, 2016 11:20 pm

Hi RealRAncor and thanks...
I used all afternoon and I did!
below the steps I made.

Tested on
O.S. Ubuntu 14.04
O.Cloud server ver. 8.1.8

needs:
-composer
-sabre

composer
command line to install composer
php composer-setup.php --install-dir=bin --filename=composer
Now just run php bin/composer in order to run Composer.

sabre/vobject
command line to install sabre using composer
composer require sabre/vobject ~4.1

now you must create this script (source from https://statuscode.ch/2015/06/Combining ... ilability/)
and put it on your server to test before putting it in a cron job to automate

<?php
// Use "composer require sabre/vobject" to get the required libraries
require_once('./vendor/autoload.php');

use Sabre\VObject;

// Configure your data
$remoteHost = 'http://xxx.xxx.xxx.xxx/owncloud';
$calendarName = 'yourcalendarname';
$username = 'usercalendarname';
$password = 'pswusercalendar';

// Get ownCloud calendar
$curl = curl_init($remoteHost . '/remote.php/caldav/calendars/'.$username.'/'.$calendarName.'?export');
curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$ics = curl_exec($curl);
curl_close($curl);

// Parse calendar file
$calendar = VObject\Reader::read($ics);

// Replace all SUMMARY fields with a value of "Reserved"
// foreach($calendar->children() as $children) {
// if($children instanceof VObject\Component\VEvent) {
// $children->SUMMARY = 'Reserved';
}
}

// Put the resulting ICS to "destinationdirectory"/public.ics
file_put_contents('Scrivania/TEST/public.ics', $calendar->serialize());
?>


to test you can write in command line:
php scriptaddress scriptname.php

attention: if you return an error like this:
PHP Warning: require_once(./vendor/autoload.php): failed to open stream:
verify you not are writing in command line as "sudo"

special thanks to the script autor Lukas Reschke
you can find other screens on my page http://2.225.140.8/viewtopic.php?f=2&t=101&p=101#p101


  • Similar Topics
    Replies
    Views
    Last post

Return to “ownCloud Server 8.0 and 8.1”

Who is online

Users browsing this forum: No registered users and 3 guests