mirror of
https://git.bolliret.ch/pcs/pcs-website
synced 2026-01-18 15:01:37 +01:00
43 lines
1.6 KiB
Bash
Executable file
43 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
ICS_URL="$1"
|
|
|
|
if [ -z "$ICS_URL" ]; then
|
|
echo "Usage: $0 <ICS_URL>"
|
|
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'
|