summaryrefslogtreecommitdiff
path: root/scripts/aoc
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/aoc')
-rwxr-xr-xscripts/aoc52
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/aoc b/scripts/aoc
new file mode 100755
index 0000000..40f94ed
--- /dev/null
+++ b/scripts/aoc
@@ -0,0 +1,52 @@
1#!/bin/sh
2
3# Set up a working environment for Advent of Code (https://adventofcode.com/).
4# Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie.
5
6# usage: aoc [yyyy nn]
7# If yyyy (year) and nn (day, with leading zero if single digit) are not
8# specified, the current year and day are used.
9
10editor="vi a.py"
11basedir="$HOME/src/aoc"
12lynx_cookie_file="$(mktemp)"
13clibrowser="lynx -cookie_file=$lynx_cookie_file"
14
15year="${1:-$(date +'%Y')}"
16day="${2:-$(date +'%d')}"
17daynozero="$(echo "$day" | sed 's/^0//')"
18
19cd "$basedir/$year/$day"
20
21# Download the puzzle input and save it to input.txt
22if [ ! -e input.txt ]; then
23 url="https://adventofcode.com/$year/day/$daynozero/input"
24 curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt
25fi
26
27# Download the problem statement page and split out the code blocks
28url="https://adventofcode.com/$year/day/$daynozero"
29curl "$url" | sed -n '/<pre><code>/,/<\/code><\/pre>/ p' | (\
30 i=1
31 rm -f "code-$i.txt"
32 IFS=''
33 while read -r line; do
34 if [ "$line" = "</code></pre>" ]; then
35 i=$((i + 1))
36 rm -f "code-$i.txt"
37 else
38 echo "$line" | sed 's/<.*>//g' >> "code-$i.txt"
39 fi
40 done
41)
42
43# Open a tmux session with lynx in its own windows, and an editor and a
44# terminal in split view.
45printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \
46 "$AOC_SESSION_COOKIE" > "$lynx_cookie_file"
47tmux new-session \; \
48 send-keys "$editor" C-m \; \
49 split-window -h \; \
50 select-pane -t 0 \; \
51 new-window \; \
52 send-keys "$clibrowser $url" C-m \;

Generated with cgit - Back to sebastiano.tronto.net