Upgrading to radicale 2

This commit is contained in:
2019-04-22 02:42:13 +02:00
parent 2f1c4d09dc
commit cc3140cfbb

View File

@@ -24,23 +24,24 @@ class Task:
def to_ical(self): def to_ical(self):
current_dtstamp = datetime.datetime.now().strftime('%Y%m%dT%H%M%SZ') 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')) uid = "DV-Taskmanager-{}-{}".format(self.name, self.date_end.strftime('%Y%m%d'))
c = Contentlines([ c = Contentlines([
Contentline('BEGIN:VCALENDAR'), Contentline('BEGIN:VCALENDAR'),
Contentline('VERSION:2.0'), Contentline('VERSION:2.0'),
Contentline('PRODID:-//Example Corp.//CalDAV Client//EN'), Contentline('PRODID:-//DorfsvaldNet//Pim Atutoask Client//FR'),
Contentline('BEGIN:VTODO'), Contentline('BEGIN:VTODO'),
Contentline('DTSTAMP:%s' % current_dtstamp), Contentline('DTSTAMP:%s' % current_dtstamp),
Contentline('CREATED:%s' % current_dtstamp),
Contentline('UID:%s' % uid), Contentline('UID:%s' % uid),
Contentline('SEQUENCE:%s' % '4'), Contentline('CREATED:%s' % current_dtstamp),
Contentline('LAST-MODIFIED:%s' % current_dtstamp), Contentline('LAST-MODIFIED:%s' % current_dtstamp),
Contentline('SEQUENCE:%s' % '4'),
Contentline('DESCRIPTION:%s' % self.body), Contentline('DESCRIPTION:%s' % self.body),
Contentline('SUMMARY:%s' % self.title), Contentline('SUMMARY:%s' % self.title),
Contentline('PRIORITY:%s' % 1), Contentline('PRIORITY:%s' % self.priority),
Contentline('DUE;VALUE=DATE:%s' % self.date_end.strftime('%Y%m%d')), 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('DTSTART;VALUE=DATE:%s' % self.date_begin.strftime('%Y%m%d')),
Contentline('PERCENT-COMPLETE:0'), Contentline('PERCENT-COMPLETE:0'),
Contentline('STATUS:NEEDS-ACTION'),
Contentline('END:VTODO'), Contentline('END:VTODO'),
Contentline('END:VCALENDAR') Contentline('END:VCALENDAR')
]) ])
@@ -49,10 +50,16 @@ class Task:
class Client: class Client:
def __init__(self, url): def __init__(self, url, username, password, calendar_name):
self.client = caldav.DAVClient(url) self.client = caldav.DAVClient(url, username=username, password=password)
self.principal = self.client.principal() self.principal = self.client.principal()
self.calendar = self.principal.calendar() self.calendar = None
for c in self.principal.calendars():
if c.name == calendar_name:
self.calendar = c
if self.calendar is None:
raise LookupError('No calendar named "{}"'.format(calendar_name))
def add_event(self, event): def add_event(self, event):
self.calendar.add_event(task.to_ical()) self.calendar.add_event(task.to_ical())
@@ -60,7 +67,7 @@ class Client:
# conf = load('./configuration.yml') # conf = load('./configuration.yml')
ref_date = datetime.date.today() + datetime.timedelta(days=-3) ref_date = datetime.date.today() + datetime.timedelta(days=2)
with open('./tasks.yml', 'r') as content_file: with open('./tasks.yml', 'r') as content_file:
tasks_conf = load(content_file.read()) tasks_conf = load(content_file.read())
@@ -70,7 +77,14 @@ for task_name, task_data in tasks_conf.items():
if t.date_begin.date() == ref_date: if t.date_begin.date() == ref_date:
task_list.append(t) task_list.append(t)
url = "https://ggentile:ID0t'8h6@cloud.dorfsvald.net/webdav/ggentile/calendar.ics/" username="ggentile"
client = Client(url) password="ID0t'8h6"
url = "https://cloud.dorfsvald.net/webdav/ggentile/"
calendar = "calendar"
client = Client(url, username, password, calendar)
for task in task_list: for task in task_list:
client.add_event(task) client.add_event(task)
print('process finished: {} tasks created'.format(len(task_list)))