A script to insert regulary Tasks into caldav
This commit is contained in:
@@ -25,3 +25,5 @@ Contacts:
|
|||||||
- Simplifier les contacts
|
- Simplifier les contacts
|
||||||
|
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
caldav pyyaml ipdb icalendar
|
||||||
|
|||||||
4
configuration.yml
Normal file
4
configuration.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
dav_server:
|
||||||
|
url: http://127.0.0.1:5232/webdav/
|
||||||
|
user: ggentile
|
||||||
|
pass: ID0T'8h6
|
||||||
79
dv-task-manager.py
Executable file
79
dv-task-manager.py
Executable file
@@ -0,0 +1,79 @@
|
|||||||
|
#! /home/ggentile/perso/projects/python/Envs/dorfsvald-pim/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import calendar
|
||||||
|
|
||||||
|
from yaml import load
|
||||||
|
from icalendar.parser import Contentlines, Contentline
|
||||||
|
import caldav
|
||||||
|
|
||||||
|
class Task:
|
||||||
|
def __init__(self, ref_date):
|
||||||
|
self.ref_date = ref_date
|
||||||
|
|
||||||
|
def load_data(self, name, data):
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
if data['periodicity'] == 'monthly':
|
||||||
|
self.date_begin = self.parse_date_monthly(data['date-begin'])
|
||||||
|
self.date_end = self.parse_date_monthly(data['date-end'])
|
||||||
|
elif data['periodicity'] == 'weekly':
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.title = data['title']
|
||||||
|
self.body = data['body']
|
||||||
|
self.priority = data['priority']
|
||||||
|
|
||||||
|
def parse_date_monthly(self, day):
|
||||||
|
if day < 0:
|
||||||
|
last_day_month = calendar.monthrange(self.ref_date.year, self.ref_date.month)[1]
|
||||||
|
day = last_day_month + day + 1
|
||||||
|
|
||||||
|
return datetime.date(year=self.ref_date.year, month=self.ref_date.month, day=day)
|
||||||
|
|
||||||
|
def to_ical(self):
|
||||||
|
current_dtstamp = datetime.datetime.now().strftime('%Y%m%dT%H%M%SZ')
|
||||||
|
uid = "DV-Taskmanager-%s-%s" % (self.name, self.date_end.strftime('%Y%m%d'))
|
||||||
|
c = Contentlines([
|
||||||
|
Contentline('BEGIN:VCALENDAR'),
|
||||||
|
Contentline('VERSION:2.0'),
|
||||||
|
Contentline('PRODID:-//Example Corp.//CalDAV Client//EN'),
|
||||||
|
Contentline('BEGIN:VTODO'),
|
||||||
|
Contentline('DTSTAMP:%s' % current_dtstamp),
|
||||||
|
Contentline('CREATED:%s' % current_dtstamp),
|
||||||
|
Contentline('UID:%s' % uid),
|
||||||
|
Contentline('SEQUENCE:%s' % '4'),
|
||||||
|
Contentline('LAST-MODIFIED:%s' % current_dtstamp),
|
||||||
|
Contentline('DESCRIPTION:%s' % self.body),
|
||||||
|
Contentline('SUMMARY:%s' % self.title),
|
||||||
|
Contentline('PRIORITY:%s' % 1),
|
||||||
|
Contentline('DUE;VALUE=DATE:%s' % self.date_end.strftime('%Y%m%d')),
|
||||||
|
Contentline('DTSTART;VALUE=DATE:%s' % self.date_begin.strftime('%Y%m%d')),
|
||||||
|
Contentline('PERCENT-COMPLETE:0'),
|
||||||
|
Contentline('END:VTODO'),
|
||||||
|
Contentline('END:VCALENDAR')
|
||||||
|
])
|
||||||
|
|
||||||
|
return c.to_ical()
|
||||||
|
|
||||||
|
#conf = load('./configuration.yml')
|
||||||
|
|
||||||
|
ref_date = datetime.date.today() + datetime.timedelta(days=1)
|
||||||
|
with open('./tasks.yml', 'r') as content_file:
|
||||||
|
tasks_conf = load(content_file.read())
|
||||||
|
|
||||||
|
task_list = []
|
||||||
|
for task_name, task_data in tasks_conf.items():
|
||||||
|
t = Task(ref_date);
|
||||||
|
t.load_data(task_name, task_data)
|
||||||
|
if (t.date_begin == ref_date):
|
||||||
|
task_list.append(t)
|
||||||
|
|
||||||
|
#caldav_url = "https://ggentile:ID0t'8h6@127.0.0.1:5232/webdav/ggentile/test.ics/"
|
||||||
|
caldav_url = "https://ggentile:ID0t'8h6@cloud.dorfsvald.net/webdav/ggentile/calendar.ics/"
|
||||||
|
client = caldav.DAVClient(caldav_url)
|
||||||
|
principal = client.principal()
|
||||||
|
calendar = principal.calendar()
|
||||||
|
for task in task_list:
|
||||||
|
calendar.add_event(task.to_ical())
|
||||||
21
tasks.yml
Normal file
21
tasks.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
reglement_piano:
|
||||||
|
periodicity: monthly
|
||||||
|
date-begin: -4
|
||||||
|
date-end: -1
|
||||||
|
title: Règlement Piano
|
||||||
|
body: 578236
|
||||||
|
priority: 1
|
||||||
|
declaration_polemploi:
|
||||||
|
periodicity: monthly
|
||||||
|
date-begin: 1
|
||||||
|
date-end: 10
|
||||||
|
title: Déclaration Pôle Emploi
|
||||||
|
body: coucou
|
||||||
|
priority: 1
|
||||||
|
test:
|
||||||
|
periodicity: monthly
|
||||||
|
date-begin: -2
|
||||||
|
date-end: -1
|
||||||
|
title: Test
|
||||||
|
body: coucou
|
||||||
|
priority: 1
|
||||||
Reference in New Issue
Block a user