From 294c537f3fa14b44a455dd7bf46188bbb6c49e78 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Thu, 16 Jan 2025 17:32:55 +0100 Subject: [PATCH] Create helper scripts to convert old calendar to new style. --- scripts/nc-cal-sync/helper/convert.sh | 23 +++++++++++++++++++++++ scripts/nc-cal-sync/helper/test.yq | 12 ++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 scripts/nc-cal-sync/helper/convert.sh create mode 100644 scripts/nc-cal-sync/helper/test.yq diff --git a/scripts/nc-cal-sync/helper/convert.sh b/scripts/nc-cal-sync/helper/convert.sh new file mode 100755 index 0000000..b139fa5 --- /dev/null +++ b/scripts/nc-cal-sync/helper/convert.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "calendars:" +for r in vorne mitte hinten +do + echo " $r:" + echo " id: \"$r\"" + echo " ignore: true" + echo " schedule:" + echo -n " " + ( + echo '[' + prefix_comma='' + for d in Mo Di Mi Do Fr + do + echo -n "$prefix_comma" + prefix_comma=', ' + cat ../../data/calendar.yaml | yq -cj '.calendar.'"$r.$d"' | . as $dict | [keys[] | . as $key | $dict[$key] | to_entries | [ .[], {key: "day", value: "'"$d"'"}, {key: "start", value: $key}, {key: "age", value: ""}, {key: "extern", value: false}, {key: "duration", value: (($dict[$key].slots) * 15)} ] | from_entries | del(.slots)]' + done + echo ']' + ) | jq -cj '[ .[][] ]' + echo +done diff --git a/scripts/nc-cal-sync/helper/test.yq b/scripts/nc-cal-sync/helper/test.yq new file mode 100644 index 0000000..b50ac87 --- /dev/null +++ b/scripts/nc-cal-sync/helper/test.yq @@ -0,0 +1,12 @@ +.calendar.vorne.Mo | . as $dict | + keys[] | . as $key | + $dict[$key] | to_entries | + [ + .[], + {key: "day", value: "Mo"}, + {key: "start", value: $key}, + {key: "age", value: ""}, + {key: "extern", value: false}, + {key: "duration", value: (($dict[$key].slots) * 15)} + ] | + from_entries | del(.slots)