Starting implementation of month ommission

This commit is contained in:
Guillaume G
2017-09-28 17:37:20 +02:00
parent 618eb9abc0
commit e4268049b9
2 changed files with 54 additions and 23 deletions

View File

@@ -9,28 +9,38 @@ from icalendar.parser import Contentlines, Contentline
import caldav import caldav
class Task: class Task:
def __init__(self, ref_date): def __init__(self, ref_date, name, data):
self.ref_date = ref_date self.ref_date = ref_date
def load_data(self, name, data):
self.name = name self.name = name
only = data['only'].split(',') if 'only' in data else None
if data['periodicity'] == 'monthly': if data['periodicity'] == 'monthly':
self.date_begin = self.parse_date_monthly(data['date-begin']) self.date_begin = self.parse_date_monthly(data['date-begin'], only)
self.date_end = self.parse_date_monthly(data['date-end']) self.date_end = self.parse_date_monthly(data['date-end'], only)
elif data['periodicity'] == 'weekly': elif data['periodicity'] == 'weekly':
pass pass
self.title = data['title'] self.title = data['title']
self.body = data['body'] self.body = data['body']
self.priority = data['priority'] self.priority = data['priority']
def parse_date_monthly(self, day): def parse_date_monthly(self, day, only=None):
if day < 0: if day < 0:
last_day_month = calendar.monthrange(self.ref_date.year, self.ref_date.month)[1] last_day_month = calendar.monthrange(self.ref_date.year, self.ref_date.month)[1]
day = last_day_month + day + 1 day = last_day_month + day + 1
return datetime.date(year=self.ref_date.year, month=self.ref_date.month, day=day) if only is not None:
only.sort()
for selected in only:
if int(selected) >= self.ref_date.month:
month = int(selected)
break
if month is None:
month = only[0]
else:
month = self.ref_date.month
return datetime.date(year=self.ref_date.year, month=month, day=day)
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')
@@ -57,23 +67,29 @@ class Task:
return c.to_ical() return c.to_ical()
class Client:
def __init__(self, url):
self.client = caldav.DAVClient(url)
self.principal = self.client.principal()
self.calendar = self.principal.calendar()
def add_event(self, event):
self.calendar.add_event(task.to_ical())
#conf = load('./configuration.yml') #conf = load('./configuration.yml')
ref_date = datetime.date.today() + datetime.timedelta(days=1) ref_date = datetime.date.today() + datetime.timedelta(days=3)
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())
task_list = [] task_list = []
for task_name, task_data in tasks_conf.items(): for task_name, task_data in tasks_conf.items():
t = Task(ref_date); t = Task(ref_date, task_name, task_data);
t.load_data(task_name, task_data)
if (t.date_begin == ref_date): if (t.date_begin == ref_date):
task_list.append(t) task_list.append(t)
#caldav_url = "https://ggentile:ID0t'8h6@127.0.0.1:5232/webdav/ggentile/test.ics/" import ipdb; ipdb.set_trace()
caldav_url = "https://ggentile:ID0t'8h6@cloud.dorfsvald.net/webdav/ggentile/calendar.ics/" url = "https://ggentile:ID0t'8h6@cloud.dorfsvald.net/webdav/ggentile/calendar.ics/"
client = caldav.DAVClient(caldav_url) client = Client(url)
principal = client.principal()
calendar = principal.calendar()
for task in task_list: for task in task_list:
calendar.add_event(task.to_ical()) client.add_event(task)

View File

@@ -5,17 +5,32 @@ reglement_piano:
title: Règlement Piano title: Règlement Piano
body: 578236 body: 578236
priority: 1 priority: 1
loyer:
periodicity: monthly
date-begin: 1
date-end: 10
title: Loyer
body: https://fr.foncia.com/login\nA797GEA4EP23F
priority: 1
declaration_polemploi: declaration_polemploi:
periodicity: monthly periodicity: monthly
date-begin: 1 date-begin: 1
date-end: 10 date-end: 10
title: Déclaration Pôle Emploi title: Déclaration Pôle Emploi
body: coucou body: N/A
priority: 1 priority: 1
test: declaration_ae:
periodicity: monthly periodicity: monthly
date-begin: -2 only: 1,4,7,10
date-end: -1 date-begin: 1
title: Test date-end: 10
body: coucou title: Déclaration AE
body: N/A
priority: 1
facturation_x2i:
periodicity: monthly
date-begin: -4
date-end: -1
title: Facture X2I
body: N/A
priority: 1 priority: 1