From 2b067c9b3ca744fa3f79537d724580b7cdf4166b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 12 May 2011 22:40:06 +0000 Subject: added meetup date generation script --- meetup/gen_dates.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'meetup/gen_dates.sh') diff --git a/meetup/gen_dates.sh b/meetup/gen_dates.sh index 0457a39..d198c94 100755 --- a/meetup/gen_dates.sh +++ b/meetup/gen_dates.sh @@ -1,13 +1,52 @@ #!/bin/sh -DOW=`date --date="next monday" +"%d"` -DOW_TS=`date --date="next monday" +"%s"` +# how far in the future +LIMIT=3 +#DEBUG=1 +NEXT_FILE="next.html" +AFTER_FILE="after.html" -echo $DOW -echo $DOW_TS +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 -NEXT_DOW_TS=$((DOW_TS + (7 * 24 * 3600))) -NEXT_DOW=`date --date="@$NEXT_DOW_TS" +"%d"` +MEETUPS="" +CNT=0 +while true; do + if [ -n "$DEBUG" ]; then echo -n "check day($TS): "`date --date="@$TS" +"%d.%m.%Y"`; fi -echo $NEXT_DOW -echo $NEXT_DOW_TS + 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 "" >> "$AFTER_FILE.new" +mv "$NEXT_FILE.new" "$NEXT_FILE" +mv "$AFTER_FILE.new" "$AFTER_FILE" + +exit 0 \ No newline at end of file -- cgit v1.2.1