summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-12-11 22:48:45 -0500
committerJesse Luehrs <doy@tozt.net>2022-12-11 22:48:45 -0500
commit161c7e6d477d37003a92dfe48d725e89fbebd3bd (patch)
tree6c0294678841d56ff65c4f1dc6968e1ae022dd6a
parent70f6149889511f61f91f525eba5a82e938cb41ec (diff)
downloadadvent-of-code-161c7e6d477d37003a92dfe48d725e89fbebd3bd.tar.gz
advent-of-code-161c7e6d477d37003a92dfe48d725e89fbebd3bd.zip
automate submitting
-rwxr-xr-xbin/submit18
1 files changed, 18 insertions, 0 deletions
diff --git a/bin/submit b/bin/submit
new file mode 100755
index 0000000..6eac13b
--- /dev/null
+++ b/bin/submit
@@ -0,0 +1,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