-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-inputs.sh
More file actions
executable file
·30 lines (25 loc) · 837 Bytes
/
get-inputs.sh
File metadata and controls
executable file
·30 lines (25 loc) · 837 Bytes
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
#!/bin/bash
# Load cookie from .cookie file
if [[ -f .cookie ]]; then
COOKIE=$(cat .cookie | tr -d '\n\r ')
if [[ -z "${COOKIE}" ]]; then
echo "Error: .cookie file is empty" >&2
exit 1
fi
else
echo "Error: .cookie file not found" >&2
echo "Please create a .cookie file with your AoC session cookie" >&2
exit 1
fi
WHOAMI=$(whoami)
UNAME=$(uname -n)
THISYEAR=$(( $(date +%Y) - 1 ))
for (( YEAR=2015; YEAR<="${THISYEAR}"; YEAR++ )); do
for DAY in {1..25}; do
URL="https://adventofcode.com/${YEAR}/day/${DAY}/input"
OUTPUT="cmd/${YEAR}/inputs/$(printf "%02d" "${DAY}").txt"
echo "Downloading ${YEAR} day ${DAY} from ${URL}"
curl -A "${WHOAMI}-${UNAME} via curl" "${URL}" --progress-bar --cookie "session=${COOKIE}" -o "${OUTPUT}"
sleep 5
done
done