]> www.fi.muni.cz Git - aoc.git/blob - 2022/get.sh
c8eda781c5fc99af7ccfa0b31013a1741a29e7e2
[aoc.git] / 2022 / get.sh
1 #!/bin/bash
2
3 DAY=`date +%d|sed 's/ //g'`
4 URLDAY=`echo $DAY|sed 's/^0//'`
5 test -n "$1" && DAY="$1"
6 FILE="$((2*DAY - 1))in.txt"
7 COOKIE=`cat cookie`
8
9 START="6:00:02"
10 MAXWAIT=300
11 STARTSEC=`date -d "$START" "+%s"`
12 NOW=`date "+%s"`
13 WAITSEC=`expr $STARTSEC - $NOW`
14
15 if [ $WAITSEC -gt 0 -a $WAITSEC -lt $MAXWAIT ]
16 then
17         echo "Waiting for $WAITSEC seconds till $START for getting $FILE ..."
18         sleep $WAITSEC
19 fi
20
21 URL="https://adventofcode.com/2022/day/$URLDAY/input"
22 echo
23 echo "Downloading $URL to $FILE"
24 curl -s -b "$COOKIE" "$URL" --output "$FILE"
25 echo ========================================================================
26 cat "$FILE"
27 echo ========================================================================
28 echo "lines words chars"
29 wc "$FILE"
30 echo