ccchh-website/fetch-calendar.sh
jtbx 25b9ac168d
All checks were successful
/ build (pull_request) Successful in 39s
/ cleanup-staging (pull_request) Successful in 2s
fetch-calendar: set start time to 6 h in the past
Only showing the current event if it started less than 6 hours in the past
should be fine. We rarely have longer events and those usually had an
announcement post anyways.
2024-02-08 19:55:55 +01:00

25 lines
860 B
Bash
Executable file

#!/bin/sh
set -eu
ICAL_URL=https://cloud.hamburg.ccc.de/remote.php/dav/public-calendars/QJAdExziSnNJEz5g
OUTFILE=data/calendar.json
# See here for uname -s outputs: https://en.wikipedia.org/wiki/Uname#Examples
OS_TYPE=$(uname -s)
if [ "$OS_TYPE" = "Linux" ]; then
START_TIME=$(date --date="-6 hours" +%s) # now - 6 hours
END_TIME=$(date --date="+1 month" +%s) # now + 1 month
elif [ "$OS_TYPE" = "Darwin" ] || [ "$OS_TYPE" = "FreeBSD" ]; then
START_TIME=$(date -v-6H +%s) # now - 6 hours
END_TIME=$(date -v+1m +%s) # now + 1 month
else
echo "ERROR: Unsupported OS type"
return 1
fi
mkdir -p $(dirname $OUTFILE)
echo "loading calendar file..."
curl -s $ICAL_URL\?export\&accept=jcal\&expand\=1\&start\=$START_TIME\&end\=$END_TIME | jq '.[2]|map({_type:.[0]}+(.[1]|map({key:.[0],value:.[3]})|from_entries))' > $OUTFILE
echo "...done"