diff --git a/.gitignore b/.gitignore index 35b4c8cf96ac821f833acff025bd4b9cbc4a5a31..f9bcce122cf18d7bb502620ded918681ec2c72f0 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 5e56ca7bf08bb61f7b84a93aa2d37f5737e28b83..2e541441eee5c399c865e002632c3de1a87371c4 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 44bc8ee57fe997439c37f4d11bb7126d1b3da67b..da1bc99179ae41e635cf000f82771feb89cf84d4 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 49212392f84ea696deef9e18a56234de31529f25..39b5dce57d2c78d49e69866ab7062faa30457f2d 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)