From 4f0f111ed74fe3884f25bd047fbaeae2cacd2263 Mon Sep 17 00:00:00 2001 From: xelast418 Date: Thu, 7 Sep 2023 15:30:20 +1200 Subject: [PATCH] Adds support for redacting event details via a "redactAs" modify parameter --- .gitignore | 4 ++++ README.md | 1 + app/tools/tools.py | 22 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a054264..40a69eb 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,7 @@ dmypy.json .pyre/ app/config/calendar.json /app/cache/ + +#development directories +/app/config/ +.vscode diff --git a/README.md b/README.md index 259cab8..e8ac8f9 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ Only the `url` and the `name` field are mandatory. - `location`: modification to apply to the location of the events - `addPrefix`: string to add at the beginning of the field - `addSuffix`: string to add at the end of the field +- `redactAs`: Replaces the content of the field with the specified string If multiple calendars are specified in the configuration list, their events will be merged in the resulting ics feed. diff --git a/app/tools/tools.py b/app/tools/tools.py index e0aa8e2..262666b 100644 --- a/app/tools/tools.py +++ b/app/tools/tools.py @@ -34,15 +34,18 @@ The JSON configuration file used in this module has the following structure }, "name":{ "addPrefix":"str", - "addSuffix":"str" + "addSuffix":"str", + "redactAs":"str" }, "description":{ "addPrefix":"str", - "addSuffix":"str" + "addSuffix":"str", + "redactAs":"str" }, "location":{ "addPrefix":"str", - "addSuffix":"str" + "addSuffix":"str", + "redactAs":"str" } } } @@ -69,6 +72,7 @@ Only the url and the name field are mandatory. - location: modification to apply to the location of the events - addPrefix: string to add at the beginning of the field - addSuffix: string to add at the end of the field +- redactAs: string to replace the field with """ import json @@ -250,6 +254,18 @@ def modify_text(cal: Calendar, modify: dict, field_name: str) -> Calendar: elif field_name == "location": event.location = event.location + change["addSuffix"] \ if event.location is not None else change["addSuffix"] + + if "redactAs" in change: + for event in cal.events: + + if field_name == "name": + event.name = change["redactAs"] + + elif field_name == "description": + event.description = change["redactAs"] + + elif field_name == "location": + event.location = change["redactAs"] return cal