Compare commits
3 Commits
2f9dd0f98f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 27c8f731a3 | |||
| 98b71218c4 | |||
| 7cb394f804 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
.idea/
|
||||
.last.run
|
||||
configuration.yml
|
||||
tasks.yml
|
||||
test/
|
||||
27
main.py
27
main.py
@@ -1,12 +1,11 @@
|
||||
import datetime
|
||||
import os
|
||||
|
||||
from caldav.lib.error import NotFoundError
|
||||
from caldav.objects import Todo
|
||||
from yaml import load, FullLoader
|
||||
import icalendar
|
||||
from icalendar.parser import Contentlines, Contentline
|
||||
from dateutil.rrule import rrule, FREQNAMES
|
||||
import caldav
|
||||
from caldav.lib.error import NotFoundError
|
||||
|
||||
|
||||
APP_ID = 'CaldavRecurringTask'
|
||||
@@ -66,13 +65,15 @@ class Client:
|
||||
if self.calendar is None:
|
||||
raise LookupError('No calendar named "{}" found'.format(calendar_name))
|
||||
|
||||
def todos(self, include_completed=True):
|
||||
return self.calendar.todos(include_completed=include_completed)
|
||||
|
||||
def add_todo(self, new_task):
|
||||
self.calendar.add_todo(new_task.to_ical())
|
||||
|
||||
def get_todo_by_uid(self, uid):
|
||||
try:
|
||||
todo = self.calendar.todo_by_uid(uid)
|
||||
# todo.percent_complete = todo.icalendar_component['PERCENT-COMPLETE']
|
||||
return todo
|
||||
except NotFoundError:
|
||||
return False
|
||||
@@ -82,7 +83,17 @@ if __name__ == "__main__":
|
||||
with open('./configuration.yml', 'r') as configuration_file:
|
||||
conf = load(configuration_file.read(), Loader=FullLoader)
|
||||
|
||||
ref_date = datetime.date.today() + datetime.timedelta(days=2)
|
||||
last_run_file_path = './.last.run'
|
||||
if os.path.isfile(last_run_file_path):
|
||||
with open(last_run_file_path, 'r') as last_run_file:
|
||||
run_date_str = last_run_file.readline()
|
||||
run_date = datetime.datetime.strptime(run_date_str, '%Y-%m-%d') + datetime.timedelta(days=1)
|
||||
run_date = run_date.date()
|
||||
else:
|
||||
run_date = datetime.date.today()
|
||||
|
||||
while run_date <= datetime.date.today():
|
||||
ref_date = run_date + datetime.timedelta(days=2)
|
||||
with open('tasks.yml', 'r') as content_file:
|
||||
tasks_conf = load(content_file.read(), Loader=FullLoader)
|
||||
|
||||
@@ -106,4 +117,8 @@ if __name__ == "__main__":
|
||||
|
||||
client.add_todo(task)
|
||||
|
||||
print('process finished: {} tasks created'.format(len(task_list)))
|
||||
print('process finished for date {}: {} tasks created'.format(run_date, len(task_list)))
|
||||
run_date = run_date + datetime.timedelta(days=1)
|
||||
|
||||
with open(last_run_file_path, 'w') as last_run_file:
|
||||
last_run_file.write(str(datetime.date.today()))
|
||||
|
||||
Reference in New Issue
Block a user