-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-input.sh
executable file
·76 lines (63 loc) · 1.24 KB
/
get-input.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Common functions
function real_base_name () {
target=$1
(
while true; do
cd "$(dirname "$target")"
target=$(basename "$target")
link=$(readlink "$target")
test "$link" || break
target=$link
done
echo "$(pwd -P)"
)
}
function output () {
echo "$@"
}
function output_error () {
>&2 echo "$@"
}
function fail () {
>&2 echo "$@"
exit 1
}
function usage {
output_error "Usage: $BASH_SOURCE [--year <YEAR> --day <DAY> --token <TOKEN>]"
output_error "--year: Year"
output_error "--day: Day"
output_error "--token: Token"
exit 1
}
YEAR="$(date +"%Y")"
DAY="$(date +"%-d")"
TOKEN="$AOC_SESSION_TOKEN"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--day)
shift
DAY="$1"
;;
--year)
shift
YEAR="$1"
;;
--token)
shift
TOKEN="$1"
;;
*)
output_error "Unknown option: $key"
usage
;;
esac
shift # past argument or value
done
SCRIPT_DIR=$(real_base_name "$0")
cd "$SCRIPT_DIR"
mkdir -p "./src/main/resources/$YEAR"
curl --cookie "session=$TOKEN" -s "https://adventofcode.com/$YEAR/day/$DAY/input" > "./src/main/resources/${YEAR}/day${DAY}.txt"
cat "./src/main/resources/${YEAR}/day${DAY}.txt"