Skip to content

Commit

Permalink
Pad the day of directories
Browse files Browse the repository at this point in the history
  • Loading branch information
alexg-axis committed Dec 25, 2021
1 parent c04faba commit 5929211
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ set -e
year="${AOC_YEAR:-$(date +%Y)}"
month="${AOC_MONTH:-$(date +%m)}"
day="${AOC_DAY:-$(date +%-d)}"
padded_day="0$day"
padded_day="${padded_day: -2}"

if [[ ! "$month" -eq 12 ]]; then
echo "It's not december quite yet. If you wish to access previous events"
echo "specify AOC_YEAR, AOC_MONTH and AOC_DAY"
exit 1
fi

mkdir -p "$year/$day"
mkdir -p "$year/$padded_day"

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
session_cookie="$(security find-generic-password -w -a "com.adventofcode.SessionCookie")"
curl --silent --cookie "session=$session_cookie" "https://adventofcode.com/$year/day/$day" | ./scripts/html2md.py > "$year/$day/README.md"
curl --silent --cookie "session=$session_cookie" "https://adventofcode.com/$year/day/$day/input" > "$year/$day/input.txt"
curl --silent --cookie "session=$session_cookie" "https://adventofcode.com/$year/day/$day" | ./scripts/html2md.py > "$year/$padded_day/README.md"
curl --silent --cookie "session=$session_cookie" "https://adventofcode.com/$year/day/$day/input" > "$year/$padded_day/input.txt"

echo "$day/12 $year initialized successfully in ./$year/$day" >&2
echo "$day/12 $year initialized successfully in ./$year/$padded_day" >&2

0 comments on commit 5929211

Please sign in to comment.