From e2d2ca4afdf74fa1eaee7bad38e1e63f69c6e5ce Mon Sep 17 00:00:00 2001 From: Reto Bollinger Date: Sat, 16 Nov 2024 12:27:36 +0100 Subject: [PATCH] Creating a script that reads out dates from public ICS and converts it into md table. --- lektor/lektordata/scripts/calendar-fetcher.sh | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 lektor/lektordata/scripts/calendar-fetcher.sh diff --git a/lektor/lektordata/scripts/calendar-fetcher.sh b/lektor/lektordata/scripts/calendar-fetcher.sh new file mode 100755 index 0000000..399e645 --- /dev/null +++ b/lektor/lektordata/scripts/calendar-fetcher.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +ICS_URL="$1" + +if [ -z "$ICS_URL" ]; then + echo "Usage: $0 " + exit 1 +fi + +ICS_DATA=$(curl -s "$ICS_URL") + +echo "| Datum | Anlass | Zeit | Ort |" +echo "|-------|--------|------|-----|" + +#original statement: +#awk 'BEGIN{FS=":"}/^DTSTART/{dtstart=$2}/^SUMMARY/{summary=$2}/^END:VEVENT/{print substr(dtstart,7,2)"/"substr(dtstart,5,2)"/"substr(dtstart,1,4),sprintf("%02d",substr(dtstart,10,2)+3)":"substr(dtstart,12,2),summary}' file.txt +#from here: https://stackoverflow.com/questions/74111401/parse-ics-and-create-output + +echo "$ICS_DATA" | awk 'BEGIN{FS=":"} +/^DTSTART/{dtstart=$2} +/^SUMMARY/{summary=$2} +/^LOCATION/{location=$2} +/^END:VEVENT/{ + gsub(/\r/, "", summary) + gsub(/\r/, "", location) + if (dtstart == "") dtstart = "Kein Datum" + if (summary == "") summary = "Kein Titel" + if (location == "") location = "Kein Ort" + + date_str = substr(dtstart, 1, 4) "-" substr(dtstart, 5, 2) "-" substr(dtstart, 7, 2) + cmd = "LC_TIME=de_DE.UTF-8 date -j -f \"%Y-%m-%d\" \"" date_str "\" +%a" + cmd | getline weekday + close(cmd) + + orderstartdate=sprintf("%s", substr(dtstart,1,8)) + realstartdate=sprintf("%s. %s. %s. %s", weekday, substr(dtstart,7,2), substr(dtstart,5,2), substr(dtstart,1,4)) + starttime=sprintf("%02d:%02d", substr(dtstart,10,2), substr(dtstart,12,2)) + summarystring=sprintf("%s", summary) + locationstring=sprintf("%s", location) + wholeline=sprintf("%s | %s | %s | %s | %s |", orderstartdate, realstartdate, starttime, summarystring, location) + gsub(/\| 00:00 \|/, "| |", wholeline) + print wholeline +}' | sort | awk '{$1=""}1' | awk '{$1=$1}1'