Skip to content

Instantly share code, notes, and snippets.

@evanrelf
Created October 26, 2023 01:10
Show Gist options
  • Save evanrelf/bc16ab6781bb2c8b3f69a9d67acd4e7b to your computer and use it in GitHub Desktop.
Save evanrelf/bc16ab6781bb2c8b3f69a9d67acd4e7b to your computer and use it in GitHub Desktop.
Offline Advent of Code
#!/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"
#!/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
@Ogaday
Copy link

Ogaday commented Dec 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment