diff options
author | Christian Pointner <equinox@ffgraz.net> | 2011-05-12 22:40:06 +0000 |
---|---|---|
committer | Christian Pointner <equinox@ffgraz.net> | 2011-05-12 22:40:06 +0000 |
commit | 2b067c9b3ca744fa3f79537d724580b7cdf4166b (patch) | |
tree | 0f455dc62e60d7bd7fefa20587422488e5b91992 /meetup/gen_dates.sh | |
parent | 41a1d4e4bc6de805c30b47fc3920538de961d518 (diff) |
added meetup date generation script
Diffstat (limited to 'meetup/gen_dates.sh')
-rwxr-xr-x | meetup/gen_dates.sh | 55 |
1 files changed, 47 insertions, 8 deletions
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 "<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
\ No newline at end of file |