From 393d7f4fc4cb5183f1303e746c007dbcd6ee377b Mon Sep 17 00:00:00 2001 From: "Lennart J. Kurzweg (Nx2)" Date: Sat, 31 May 2025 13:35:52 +0200 Subject: [PATCH] campuszeit --- home-modules/calendar-campuszeit-fix.nix | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 home-modules/calendar-campuszeit-fix.nix diff --git a/home-modules/calendar-campuszeit-fix.nix b/home-modules/calendar-campuszeit-fix.nix new file mode 100644 index 0000000..d15769f --- /dev/null +++ b/home-modules/calendar-campuszeit-fix.nix @@ -0,0 +1,58 @@ +{ pkgs, user, ... }: +{ + home.packages = let + u = pkgs.writers.writePython3Bin "nx_fix_campuszeit_python" { + flakeIgnore = [ "E302" "E305" "E226" "E501" ]; + } /* python */ '' +import os +import sys + +def replace_campus_timezone(directory): + if not os.path.isdir(directory): + print(f"Error: {directory} is not a valid directory.") + return + + for filename in os.listdir(directory): + filepath = os.path.join(directory, filename) + if not os.path.isfile(filepath): + continue + + with open(filepath, 'r', encoding='utf-8') as f: + content = f.read() + + if 'TZID:Europe/Berlin' in content or 'TZID="Europe/Berlin"' in content: + # Remove VTIMEZONE block for CampusNetZeit (optional depending on needs) + # Use a regex if multiple VTIMEZONE blocks may exist + start_idx = content.find('BEGIN:VTIMEZONE') + end_idx = content.find('END:VTIMEZONE', start_idx) + if start_idx != -1 and end_idx != -1: + content = content[:start_idx] + content[end_idx + len('END:VTIMEZONE\n'):] + + # Replace all TZID references + content = content.replace('TZID:Europe/Berlin', 'TZID:Europe/Berlin') + content = content.replace('TZID="Europe/Berlin"', 'TZID="Europe/Berlin"') + + with open(filepath, 'w', encoding='utf-8') as f: + f.write(content) + + print(f"Updated time zone in: {filename}") + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python replace_timezone.py ") + else: + replace_campus_timezone(sys.argv[1]) +''; + in [ + (pkgs.writeShellApplication { + name = "nx_fix_campuszeit"; + text = /*bash*/ '' + echo CHANGING OWNERSHIP OF "$(realpath "$1")" RECURSIVELY + read -r -p "Continue?" + sudo chown -R ${user} "$1" + ${u}/bin/nx_fix_campuszeit_python "$1" + sudo chown -R radicale "$1" + ''; + }) + ]; +}