diff options
Diffstat (limited to 'meetup/gen_dates_tech.sh')
-rwxr-xr-x | meetup/gen_dates_tech.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/meetup/gen_dates_tech.sh b/meetup/gen_dates_tech.sh new file mode 100755 index 0000000..0bc4479 --- /dev/null +++ b/meetup/gen_dates_tech.sh @@ -0,0 +1,58 @@ +#!/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" + +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 + +MEETUPS="" +CNT=0 +while true; do + if [ -n "$DEBUG" ]; then echo -n "check day($TS): "`date --date="@$TS" +"%d.%m.%Y"`; fi + + if [ $DOM -le 7 ] || ([ $DOM -ge 15 ] && [ $DOM -le 21 ]); then + if [ -n "$DEBUG" ]; then echo " -> ok"; fi + MEETUPS="$MEETUPS $TS" + 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=$@ + +date --date="@$NEXT" +"%d.%m.%Y" > "$NEXT_FILE.new" +echo "<ul>" > "$AFTER_FILE.new" +for meetup in $FUTURE; do + echo " <li>"`date --date="@$meetup" +"%d.%m.%Y"`"</li>" >> "$AFTER_FILE.new" + +done +echo "</ul>" >> "$AFTER_FILE.new" +mv "$NEXT_FILE.new" "$NEXT_FILE" +mv "$AFTER_FILE.new" "$AFTER_FILE" + +exit 0 |