Add automated download script

This commit is contained in:
2020-12-02 21:20:12 +01:00
parent 2d58f0eb23
commit 877bf933d0

26
2020/download.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
if [[ -z $AOC_SESSION ]]; then
echo "AOC_SESSION not set"
exit 1
fi
if [[ $# -ge 1 ]]; then
# Get rid of leading zeroes
(( DAY = $1 * 1 ))
else
DAY=$(date +%-d)
fi
TARGET_FILE=$(printf "inputs/%02d.txt" "$DAY")
echo "Going to download day $DAY to $TARGET_FILE"
if [[ -s $TARGET_FILE ]]; then
echo "Target file exists"
else
curl --output "$TARGET_FILE" \
--header "Cookie: session=$AOC_SESSION" \
--fail \
"https://adventofcode.com/2020/day/$DAY/input"
fi