#!/bin/sh # generates the upcoming meetups for Funkfeuer Graz Homepage # # this script should be called by cron every day (night) # how far in the future should i go? LIMIT=3 # uncomment to enable debug #DEBUG=1 # where to put the output files? NEXT_FILE="next.html" AFTER_FILE="after.html" NEXTTYPE_FILE="nexttype.html" NEXT_BEGINTIME_FILE="nextbegin.html" DOW=`date +"%u"` if [ $DOW -eq 1 ]; then DOM=`date +"%e"` TS=`date +"%s"` else DOM=`date --date="next monday" +"%e"` TS=`date --date="next monday" +"%s"` fi if [ $TS -lt $(date --date="2023-08-22" +"%s") ]; then # skip specific date # (only works if it's already that day - for future cases specify exact upcoming date below!) DOM=`date --date="next monday" +"%e"` TS=`date --date="next monday" +"%s"` fi MEETUPS="" MEETUPTYPES="" CNT=0 while true; do if [ -n "$DEBUG" ]; then echo -n "check day($TS): "`date --date="@$TS" +"%d.%m.%Y"`; fi #skip specific date in future ymd_to_skip="2024-04-01" ymd=$(date --date=@$TS +"%Y-%m-%d") if [ $ymd = $ymd_to_skip ]; then TS=$((TS + (7 * 24 * 3600))) DOM=`date --date="@$TS" +"%e"` continue fi if [ $DOM -le 7 ] || ([ $DOM -ge 15 ] && [ $DOM -le 21 ]); then if [ $DOM -le 7 ]; then MTYP="Tech/Core Treffen" BEGINTIME="20:30" else MTYP="allgemeines Funkfeuertreffen" BEGINTIME="20:30" fi if [ -n "$DEBUG" ]; then echo " -> ok $MTYP"; fi MEETUPS="$MEETUPS $TS" MEETUPTYPES="$MEETUPTYPES $MTYP" CNT=$((CNT + 1)) if [ $CNT -ge $LIMIT ]; then break; fi else if [ -n "$DEBUG" ]; then echo ""; fi fi TS=$((TS + (7 * 24 * 3600))) DOM=`date --date="@$TS" +"%e"` done set -- $MEETUPS NEXT=$1 shift FUTURE=$@ set -- $MEETUPTYPES NEXTMTYP=$1 shift FUTUREMTYP=$@ date --date="@$NEXT" +"%d.%m.%Y" > "$NEXT_FILE.new" echo $NEXTMTYP > "$NEXTTYPE_FILE.new" echo $BEGINTIME > "$NEXT_BEGINTIME_FILE.new" CNT=0 echo "" >> "$AFTER_FILE.new" mv "$NEXT_FILE.new" "$NEXT_FILE" mv "$NEXT_BEGINTIME_FILE.new" "$NEXT_BEGINTIME_FILE" mv "$NEXTTYPE_FILE.new" "$NEXTTYPE_FILE" mv "$AFTER_FILE.new" "$AFTER_FILE" exit 0