-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday
More file actions
executable file
·38 lines (32 loc) · 1.35 KB
/
day
File metadata and controls
executable file
·38 lines (32 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/zsh
# set TZ so that we get the correct day within the first 24 hours of the published puzzle
export TZ=America/New_York
# The URL uses un-padded day numbers, but we use 0-padded day numbers for the code and input file names.
# Thus, we build 2 day variables
dd=${1:-$(date '+%d')}
d=$dd
[[ "${d[1]}" -eq 0 ]] && d="${dd[2]}"
[[ ${#dd} -eq 1 ]] && dd="0$dd"
input="input/Day$dd.txt"
url="https://adventofcode.com/2024/day/$d/input"
dir="src/test/kotlin"
template="$dir/Template.kt"
code="$dir/Day$dd.kt"
session="session"
if [[ ! -s "$code" ]]; then
sed -e "s/class Template/class Day$dd/" "$template" > "$code"
git add "$code"
fi
# The input is not the same for all participants, and we thus must pass our session cookie when downloading. If you need
# to renew the cookie, log into the web site, then copy the session cookie value from the "Storage" tab of "Web
# Developer Tools" into the session file.
if [[ ! -s "$input" ]]; then
if [[ ! -s "$session" ]]; then
echo "Login to the Aoc website https://adventofcode.com/ and then save the 'session' cookie value in the '$session' file"
exit 1
fi
if ! https --download --verify=no --output="$input" "$url" "Cookie:session=$(< $session)" >& /dev/null; then
echo "Login to the Aoc website https://adventofcode.com/ and then update the '$session' file with the 'session' cookie value"
exit 1
fi
fi