From 8e8743b5af6ac07f70c76722c5510876e7ab3cd4 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Thu, 1 Dec 2022 06:06:01 +0100 Subject: [PATCH] get.sh - day in URL is w/o leading sero --- 2022/get.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 2022/get.sh diff --git a/2022/get.sh b/2022/get.sh new file mode 100755 index 0000000..c8eda78 --- /dev/null +++ b/2022/get.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +DAY=`date +%d|sed 's/ //g'` +URLDAY=`echo $DAY|sed 's/^0//'` +test -n "$1" && DAY="$1" +FILE="$((2*DAY - 1))in.txt" +COOKIE=`cat cookie` + +START="6:00:02" +MAXWAIT=300 +STARTSEC=`date -d "$START" "+%s"` +NOW=`date "+%s"` +WAITSEC=`expr $STARTSEC - $NOW` + +if [ $WAITSEC -gt 0 -a $WAITSEC -lt $MAXWAIT ] +then + echo "Waiting for $WAITSEC seconds till $START for getting $FILE ..." + sleep $WAITSEC +fi + +URL="https://adventofcode.com/2022/day/$URLDAY/input" +echo +echo "Downloading $URL to $FILE" +curl -s -b "$COOKIE" "$URL" --output "$FILE" +echo ======================================================================== +cat "$FILE" +echo ======================================================================== +echo "lines words chars" +wc "$FILE" +echo -- 2.43.5