diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-03-14 20:26:12 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-03-14 20:26:12 +0100 |
commit | 75eaaab9cc29c301112404594be02b1b71caeecf (patch) | |
tree | ef440273352e43f1c5fe08fef28c9712311d2a1a | |
parent | 072a0971c29037bf26e1a7092b93ca28f6c4f2bb (diff) |
generating tasks works
-rwxr-xr-x | main.py | 68 |
1 files changed, 35 insertions, 33 deletions
@@ -1,7 +1,7 @@ #!/bin/python3 from libdecsync import Decsync -from icalendar import Calendar, Event +from icalendar import Calendar, Todo from taggen import tag_gen from datetime import datetime from uuid import uuid4 @@ -13,49 +13,51 @@ import requests APPID = "brightspace-decsync" def load_config(): - config_file = open("./config.json", "r") - config_json = json.loads(config_file.read()) - config_json["decsync"]["dir"] = os.path.expanduser(config_json["decsync"]["dir"]) - return config_json + config_file = open("./config.json", "r") + config_json = json.loads(config_file.read()) + config_json["decsync"]["dir"] = os.path.expanduser(config_json["decsync"]["dir"]) + return config_json def get_brightspace_events(config): - request = requests.get(config["brightspace"]) - cal = Calendar.from_ical(request.text) - return list(cal.walk('vevent')) + request = requests.get(config["brightspace"]) + cal = Calendar.from_ical(request.text) + return list(cal.walk('vevent')) -def create_task_ical(cal_event): - cal = Calendar() - event = Event() - cal.add('prodid', APPID) - cal.add('version', '2.0') +def create_task_ical(event): + cal = Calendar() + todo = Todo() + cal.add('prodid', APPID) + cal.add('version', '2.0') - event.add("priority", 9) - event.add("status", "needs-action") + todo.add("priority", 9) + todo.add("status", "needs-action") - tag = tag_gen(cal_event.get('location')) - if tag: event.add("categories", tag) + tag = tag_gen(event.get('location')) + if tag: todo.add("categories", [tag]) - event.add("created", datetime.now()) + todo.add("created", datetime.now()) - event.add("dtstamp", str(cal_event.get('dtstart'), 'utf-8')) - event.add("uid", uuid4()) + todo.add("dtstamp", event.decoded('dtstart')) + todo.add("uid", uuid4()) - event.add("summary", str(cal_event.get('summary'), 'utf-8')) - event.add("description", str(cal_event.get('description'), 'utf-8')) - cal.add_component(event) - return cal.to_ical() + todo.add("summary", event.decoded('summary')) + description = event.get('description') + if description: todo.add("description", description) + + cal.add_component(todo) + return cal.to_ical() def task_handler(config, ds, event): - epoch = time.time() - timestamp = f"{int(epoch)}{int((epoch % 1) * 10 ** 9)}" - ds.set_entry(["resources", timestamp], None, create_task_ical(event)) + epoch = time.time() + timestamp = f"{int(epoch)}{int((epoch % 1) * 10 ** 9)}" + ds.set_entry(["resources", timestamp], None, str(create_task_ical(event), 'utf-8')) def main(): - config = load_config() - ds = Decsync(config["decsync"]["dir"], "tasks", config["decsync"]["collection"], APPID) - events = get_brightspace_events(config) - for event in events: - task_handler(config, ds, event) + config = load_config() + ds = Decsync(config["decsync"]["dir"], "tasks", config["decsync"]["collection"], APPID) + events = get_brightspace_events(config) + for event in events: + task_handler(config, ds, event) if __name__ == "__main__": - main() + main() |