-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoc.sh
More file actions
executable file
·42 lines (37 loc) · 1.31 KB
/
aoc.sh
File metadata and controls
executable file
·42 lines (37 loc) · 1.31 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
39
40
41
42
#!/bin/bash
my_dir="$(dirname "$(realpath "$0")")"
cookie_file="${my_dir}/cookie"
cookie="$(cat "${cookie_file}")"
usage="Advent of Code helper
$(basename "$0") <year> <day>
$(basename "$0") <year> <day> input
$(basename "$0") <year> <day> answer <part> <answer>"
year="$1"
day="$2"
action="$3"
part="$4"
answer="$5"
endpoint="https://adventofcode.com/${year}/day/${day}"
flags="--cookie session=${cookie} --silent --show-error"
if [[ "$1" == "help" || "$1" == "--help" || "$1" == "-h" || "$1" == "/?" || "$1" == "?" ]]; then
echo "${usage}"
elif [[ -z "${action}" && -n ${year} && -n ${day} ]]; then
# Word splitting intended
# shellcheck disable=SC2086
curl ${flags} "${endpoint}" | grep -A9999 "<article" | grep -B9999 "</article>" | html2text
elif [[ "${action}" == "input" ]]; then
# Word splitting intended
# shellcheck disable=SC2086
curl ${flags} "${endpoint}/input"
elif [[ "${action}" == "answer" ]]; then
# Word splitting intended
# shellcheck disable=SC2086
curl ${flags} "${endpoint}/answer" --data-raw "level=${part}&answer=${answer}" | grep -A9999 "<article" | grep -B9999 "</article>" | html2text
elif [[ "${action}" == "input" ]]; then
# Word splitting intended
# shellcheck disable=SC2086
curl ${flags} "${endpoint}/input"
else
echo "${usage}"
exit 1
fi