Created
October 26, 2023 01:10
-
-
Save evanrelf/bc16ab6781bb2c8b3f69a9d67acd4e7b to your computer and use it in GitHub Desktop.
Offline Advent of Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -Eeuo pipefail | |
IFS=$'\n\t' | |
if [ "$#" -ne 1 ]; then | |
echo "usage: ./download <year>" >&2 | |
exit 1 | |
fi | |
year=$1 | |
if [ -z "${AOC_COOKIE:-}" ]; then | |
echo "error: Missing AOC_COOKIE" >&2 | |
exit 1 | |
fi | |
if [ ! -e "static/style.css" ]; then | |
mkdir -p "static" | |
echo "Downloading static/style.css" | |
curl "https://adventofcode.com/static/style.css" -o "static/style.css" | |
fi | |
if [ ! -e "$year/index.html" ]; then | |
mkdir -p "$year" | |
echo "Downloading $year/index.html" | |
curl "https://adventofcode.com/$year" -o "$year/index.html" --cookie "$AOC_COOKIE" | |
fi | |
for day in $(seq 25); do | |
path="$year/day/$day" | |
mkdir -p "$path" | |
if [ ! -e "$path/index.html" ]; then | |
echo "Downloading $path/index.html" | |
curl "https://adventofcode.com/$path" -o "$path/index.html" --cookie "$AOC_COOKIE" | |
fi | |
if [ ! -e "$path/input" ]; then | |
echo "Downloading $path/input" | |
curl "https://adventofcode.com/$path/input" -o "$path/input" --cookie "$AOC_COOKIE" | |
fi | |
done | |
echo "Done" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -Eeuo pipefail | |
IFS=$'\n\t' | |
if [ "$#" -ne 1 ]; then | |
echo "usage: ./serve <year>" >&2 | |
exit 1 | |
fi | |
year=$1 | |
echo "http://localhost:8080/$year" | |
python3 -m http.server 8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great, thanks! My only issue is that the input url generation on the puzzle page doesn't seem to work. For instance I get
http://localhost:8080/2018/day/4/4/input
on 2018, day 4. However, it's not a big issue as I do have the input on disk.