From 60052659b98832c78c902e4f27ecee2663d8e913 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 6 May 2026 08:30:49 +0200 Subject: Added scripts --- scripts/aoc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 scripts/aoc (limited to 'scripts/aoc') diff --git a/scripts/aoc b/scripts/aoc new file mode 100755 index 0000000..40f94ed --- /dev/null +++ b/scripts/aoc @@ -0,0 +1,52 @@ +#!/bin/sh + +# Set up a working environment for Advent of Code (https://adventofcode.com/). +# Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie. + +# usage: aoc [yyyy nn] +# If yyyy (year) and nn (day, with leading zero if single digit) are not +# specified, the current year and day are used. + +editor="vi a.py" +basedir="$HOME/src/aoc" +lynx_cookie_file="$(mktemp)" +clibrowser="lynx -cookie_file=$lynx_cookie_file" + +year="${1:-$(date +'%Y')}" +day="${2:-$(date +'%d')}" +daynozero="$(echo "$day" | sed 's/^0//')" + +cd "$basedir/$year/$day" + +# Download the puzzle input and save it to input.txt +if [ ! -e input.txt ]; then + url="https://adventofcode.com/$year/day/$daynozero/input" + curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt +fi + +# Download the problem statement page and split out the code blocks +url="https://adventofcode.com/$year/day/$daynozero" +curl "$url" | sed -n '/
/,/<\/code><\/pre>/ p' | (\
+	i=1
+	rm -f "code-$i.txt"
+	IFS=''
+	while read -r line; do
+		if [ "$line" = "
" ]; then + i=$((i + 1)) + rm -f "code-$i.txt" + else + echo "$line" | sed 's/<.*>//g' >> "code-$i.txt" + fi + done +) + +# Open a tmux session with lynx in its own windows, and an editor and a +# terminal in split view. +printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ + "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" +tmux new-session \; \ + send-keys "$editor" C-m \; \ + split-window -h \; \ + select-pane -t 0 \; \ + new-window \; \ + send-keys "$clibrowser $url" C-m \; -- cgit v1.3