From 72260704af6c29267b71c9a5738869603bfb8103 Mon Sep 17 00:00:00 2001 From: TheJoeCoder <joe@radialbog9.uk> Date: Sun, 1 Jun 2025 23:35:42 +0100 Subject: [PATCH] Improve documentation and prevent broken parts of code from working --- .gitignore | 1 + .vscode/settings.json | 2 +- PATCHES.md | 26 +++++++++++++++++++- main.py | 57 ++++++++++++++++++++++++++----------------- 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 35b4c8c..f9bcce1 100644 --- a/.gitignore +++ b/.gitignore @@ -421,5 +421,6 @@ $RECYCLE.BIN/ config.json patches.json patches.json.old +patches.*.json input.json output.ics \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 5e56ca7..2e54144 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "python.languageServer": "Pylance", + "python.languageServer": "Jedi", "python.analysis.diagnosticSeverityOverrides": { "reportMissingModuleSource": "none", "reportShadowedImports": "none" diff --git a/PATCHES.md b/PATCHES.md index 44bc8ee..da1bc99 100644 --- a/PATCHES.md +++ b/PATCHES.md @@ -51,4 +51,28 @@ Arguments: - `>` greater than - `<` less than - `>=` greater then/equal to - - `<=` less than/equal to \ No newline at end of file + - `<=` less than/equal to + +--- + +## Operations + +**edit** - merges the arguments with the lesson's json object +- `edit` - the json to merge + +--- + +**edit_times** - edits the start and end time of a lesson +- `edit` object containing at least one of the following: + - `start` - the start time + - `end` - the end time + +*WARNING*: Be very careful of timezones! While the times of lessons from input are interpreted in the system's timezone, start and end times in this operation are interpreted as UTC! Specify a timezone by appending to the end of the time (e.g. Z for UTC, +01:00 for BST, etc.). + +--- + +**add**: adds a lesson on specific days +- `days` - a list of days to add the lesson (named e.g. ["Monday", "Tuesday"]) +- `start_time` - the start time +- `length` - the length of the lesson, as an integer, in minutes +- `data` - the lesson data as if lesson was from Bromcom \ No newline at end of file diff --git a/main.py b/main.py index 4921239..39b5dce 100644 --- a/main.py +++ b/main.py @@ -146,9 +146,20 @@ def apply_patch(input_lessons: list, patch: dict, week_lookup_table: list) -> li if "end" in patch["edit"]: end_time = datetime.time.fromisoformat(patch["edit"]["end"]) end_date = end_date.replace(hour=end_time.hour, minute=end_time.minute, second=end_time.second) + + start_date_formatted = start_date.strftime("%Y-%m-%dT%H:%M:%S") + end_date_formatted = end_date.strftime("%Y-%m-%dT%H:%M:%S") + + if end_date < start_date: + logger.warn( + f"For lesson {lesson.get("period", "no-period")} on {start_date.strftime("%Y-%m-%d")}: " + + f"end date is before start date ({start_date_formatted} vs {end_date_formatted}). Skipped" + ) + continue + # Set new dates - lesson["startDate"] = start_date.strftime("%Y-%m-%dT%H:%M:%S") - lesson["endDate"] = end_date.strftime("%Y-%m-%dT%H:%M:%S") + lesson["startDate"] = start_date_formatted + lesson["endDate"] = end_date_formatted elif patch["type"] == "add": # Add a lesson # Build day map @@ -235,29 +246,29 @@ if __name__ == "__main__": #) #school_attendee.user_type = "GROUP" - class_attendee = Attendee( - email=f"{lesson['class']}" - ) - class_attendee.user_type = "GROUP" - class_attendee.role = "REQ-PARTICIPANT" - class_attendee.rsvp = "False" + #class_attendee = Attendee( + # email=f"{lesson['class']}" + #) + #class_attendee.user_type = "GROUP" + #class_attendee.role = "REQ-PARTICIPANT" + #class_attendee.rsvp = "False" # ^ Might be a temporary bug with ics, # setting to a string works so not gonna change it - class_attendee.status = "ACCEPTED" + #class_attendee.status = "ACCEPTED" - teacher_attendee = Attendee( - email=f"{lesson['teacherName']}" - ) - teacher_attendee.user_type = "INDIVIDUAL" - teacher_attendee.role = "REQ-PARTICIPANT" - teacher_attendee.rsvp = "False" - teacher_attendee.status = "ACCEPTED" + #teacher_attendee = Attendee( + # email=f"{lesson['teacherName']}" + #) + #teacher_attendee.user_type = "INDIVIDUAL" + #teacher_attendee.role = "REQ-PARTICIPANT" + #teacher_attendee.rsvp = "False" + #teacher_attendee.status = "ACCEPTED" - e_attendees = [ - # school_attendee, - class_attendee, - teacher_attendee - ] + #e_attendees = [ + # # school_attendee, + # class_attendee, + # teacher_attendee + #] # Create event event = Event( @@ -265,11 +276,11 @@ if __name__ == "__main__": begin=e_begin, end=e_end, location=e_location, - attendees=e_attendees, + #attendees=e_attendees, created=datetime.datetime.now() ) - event.extra.append(ContentLine(name="COLOR", value=f"#{lesson['subjectColour']}")) + #event.extra.append(ContentLine(name="COLOR", value=f"#{lesson['subjectColour']}")) # Add event to calendar cal.events.append(event) -- GitLab