-
-
Save XavierChanth/3b027e0cdab863b6ea861894b4b1bfc4 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