From fe601d453f8b4c00dc12fd8945be0efffe9f8165 Mon Sep 17 00:00:00 2001 From: cos Date: Wed, 1 Dec 2021 09:54:18 +0100 Subject: Minor changes to fetch_input --- bin/fetch_input.sh | 9 ++++++--- 1 file 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.*\(.*\).*#\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 -- cgit v1.2.3