summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fetch_input.sh9
1 files changed, 6 insertions, 3 deletions
diff --git a/bin/fetch_input.sh b/bin/fetch_input.sh
index 3467871..6b27931 100755
--- a/bin/fetch_input.sh
+++ b/bin/fetch_input.sh
@@ -1,4 +1,4 @@
-#!/bin/sh -e
+#!/bin/sh -eu
COOKIES="${HOME}/.adventofcode.json"
@@ -35,7 +35,9 @@ if [ "${MODE}" = 'wget' ]; then
# https://stackoverflow.com/q/21919156/how-do-i-copy-cookies-from-chrome
SESSION=$(jq < "${COOKIES}" '."session-cookie"' | tr -d '"')
- [ -e "input" ] || {
+ if [ -e "input" ]; then
+ echo 'Directory input already exists. Skipping.'
+ else
mkdir 'input'
authenticated_wget --output-document "input/page_${DEC}.html" \
"https://adventofcode.com/${YEAR}/day/${DEC}"
@@ -43,10 +45,11 @@ if [ "${MODE}" = 'wget' ]; then
"https://adventofcode.com/${YEAR}/settings")
USERNAME=$(echo "${SETTINGS}" |
sed -n 's#.*display_name.*checked.*<span>\(.*\)</span>.*#\1#p')
+ echo "Found username: ${USERNAME}"
authenticated_wget --output-document "input/${USERNAME}" \
"https://adventofcode.com/${YEAR}/day/${DEC}/input"
elinks -dump "./input/page_${DEC}.html" >"input/page_${DEC}.txt"
- }
+ fi
elif [ "${MODE}" = 'aocdl' ]; then
# One could possibly use the golang implemenation instead of wget:
# https://github.com/GreenLightning/advent-of-code-downloader