aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--license21
-rwxr-xr-xmain.py38
-rw-r--r--readme.md23
-rw-r--r--requirements.txt3
-rw-r--r--taggen.py15
6 files changed, 105 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2fd833a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+config.json
+
+# python files
+venv/
+__pycache__/
diff --git a/license b/license
new file mode 100644
index 0000000..46973e2
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 lonkaars
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/main.py b/main.py
new file mode 100755
index 0000000..9339059
--- /dev/null
+++ b/main.py
@@ -0,0 +1,38 @@
+#!/bin/python3
+
+from libdecsync import Decsync
+from icalendar import Calendar
+from taggen import tag_gen
+import time
+import json
+import os
+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
+
+def get_brightspace_events(config):
+ request = requests.get(config["brightspace"])
+ cal = Calendar.from_ical(request.text)
+ return list(cal.walk('vevent'))
+
+def task_handler(config, ds, event):
+ epoch = time.time()
+ timestamp = f"{int(epoch)}{int((epoch % 1) * 10 ** 9)}"
+ print(timestamp)
+ ds.set_entry(["resources", timestamp], None, "ical content here")
+
+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)
+
+if __name__ == "__main__":
+ main()
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..9603715
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,23 @@
+# brightspace-decsync
+
+utility that converts brightspace calendar events to decsync tasks
+
+## dependencies
+
+```
+python3 -m venv venv
+source venv/bin/activate
+pip3 install -r requirements.txt
+```
+
+## config.json
+
+```
+{
+ "decsync": {
+ "dir": "<decsync dir>",
+ "collection": "<collection uuid for tasks>"
+ },
+ "brightspace": "<brightspace calendar id w/ token url argument>"
+}
+```
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..55d7af6
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,3 @@
+icalendar==4.0.9
+libdecsync==2.2.1
+requests==2.27.1
diff --git a/taggen.py b/taggen.py
new file mode 100644
index 0000000..3d36e87
--- /dev/null
+++ b/taggen.py
@@ -0,0 +1,15 @@
+import re
+
+def tag_gen(input_str):
+ input_str = input_str.lower()
+ input_str = re.sub(r'aii', '', input_str)
+ input_str = re.sub(r'20\d{2}-\d{2}', '', input_str)
+ input_str = re.sub(r'[pb]\d+', '', input_str)
+ input_str = re.sub(r'\d', '', input_str)
+ input_str = re.sub(r'blok', '', input_str)
+ input_str = re.sub(r'programmeren c', 'programmeren', input_str)
+ input_str = re.sub(r'stylofoon', '', input_str)
+ input_str = re.sub(r'[-]', '', input_str)
+ input_str = re.sub(r'\s+', ' ', input_str)
+ return input_str.strip()
+