summaryrefslogtreecommitdiffstats
path: root/bin/submit
blob: 6eac13be6bae0a4d23cab0ab37f7dc43a0e52470 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh
set -eu

part=$1
day=${2:-$(date +%-d)}
year=${3:-$(date +%Y)}

read -r line
out=$(curl -i -H 'User-Agent: https://github.com/doy/advent-of-code by adventofcode@tozt.net' -b "$(cat .cookie)" -d "level=$part&answer=$line" -s https://adventofcode.com/"$year"/day/"$day"/answer)
if echo "$out" | grep -q "You have .* left to wait."; then
  echo "$out" | grep "You have .* left to wait" | sed 's/.*\(You have .* left to wait.\).*/\1/' 
  exit 2
elif echo "$out" | grep -q "That's not the right answer"; then
  echo INCORRECT
  exit 1
else
  echo CORRECT
fi