From b9ef175cf6fa05d9f0939987592ce3ae34b94bf0 Mon Sep 17 00:00:00 2001 From: Alfred Melch Date: Thu, 2 Dec 2021 11:04:50 +0100 Subject: [PATCH] Helper script: fetch puzzle description Extended the helper script to fetch the puzzle description. It will be put into a README.md. The input will now be stored into a input folder along with examples extracted from the puzzle description. Adjusted the parsing of the day from the folder name. It will now take any number that appears in the folder name. Previously: folder name must be a number, leading zeros will be stripped (e.g 01, 02). Now: there can be other characters as well (e.g day01, day02) --- lib/aoc.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/aoc.sh b/lib/aoc.sh index b4d5725..f546a2b 100755 --- a/lib/aoc.sh +++ b/lib/aoc.sh @@ -3,14 +3,34 @@ PARENT_DIR=$(dirname $PWD) YEAR=${PARENT_DIR##*/} DAY_RAW=${PWD##*/} -DAY=$((10#$DAY_RAW)) +DAY=$((10#${DAY_RAW//[^0-9]/})) SESSION_KEY=$(cat ~/.aocrc) echo "Fetching ${YEAR} ${DAY}" echo $SESSION_KEY -curl -b session=$SESSION_KEY https://adventofcode.com/${YEAR}/day/${DAY}/input > input +URL_DAY="https://adventofcode.com/${YEAR}/day/${DAY}" +URL_INPUT="$URL_DAY/input" -echo "Visit: https://adventofcode.com/${YEAR}/day/${DAY}" +mkdir -p input +echo -e "$URL_DAY\n" > README.md + +curl -b session=$SESSION_KEY $URL_DAY | sed -n '/
/,/<\/article>/p' | html2markdown --mark-code >> README.md +curl -b session=$SESSION_KEY $URL_INPUT > input/input + +cat README.md + +echo "Extracting example code blocks..." +# extract example code blocks +cat README.md | + sed -n '/\[code\]/,/\[\/code\]/p' | # extract code blocks + sed '/^\s*$/d' | # remove empty lines + sed '/^\[\/code\]/d' | # remove closing bracket + sed 's/^ //' | # remove indentation + csplit - --suppress-matched --elide-empty-files --prefix='input/example' --suffix='%d' '/\[code\]/' '{*}' +echo "done." + +echo +echo "Visit: $URL_DAY"