diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-01 18:57:14 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-01 18:57:14 +0100 |
| commit | 183d2d20d311cdb296176496bba10e1c17f273fd (patch) | |
| tree | 6754ca8620a576f964a6fefbd83650be14e38804 /aoc | |
| parent | 7557d3b9071af21512af55c0a79da00197463abf (diff) | |
| download | scripts-183d2d20d311cdb296176496bba10e1c17f273fd.tar.gz scripts-183d2d20d311cdb296176496bba10e1c17f273fd.zip | |
aoc: download code blocks from input text
Diffstat (limited to 'aoc')
| -rwxr-xr-x | aoc | 16 |
1 files changed, 15 insertions, 1 deletions
| @@ -24,11 +24,25 @@ if [ ! -e input.txt ]; then | |||
| 24 | curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt | 24 | curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt |
| 25 | fi | 25 | fi |
| 26 | 26 | ||
| 27 | # Download the problem statement page and split out the code blocks | ||
| 28 | url="https://adventofcode.com/$year/day/$daynozero" | ||
| 29 | curl "$url" | sed -n '/<pre><code>/,/<\/code><\/pre>/ p' | (\ | ||
| 30 | i=1 | ||
| 31 | rm -f "code-$i.txt" | ||
| 32 | while read line; do | ||
| 33 | if [ "$line" = "</code></pre>" ]; then | ||
| 34 | i=$((i + 1)) | ||
| 35 | rm -f "code-$i.txt" | ||
| 36 | else | ||
| 37 | echo "$line" | sed 's/<.*>//g' >> "code-$i.txt" | ||
| 38 | fi | ||
| 39 | done | ||
| 40 | ) | ||
| 41 | |||
| 27 | # Open a tmux session with lynx in its own windows, and an editor and a | 42 | # Open a tmux session with lynx in its own windows, and an editor and a |
| 28 | # terminal in split view. | 43 | # terminal in split view. |
| 29 | printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ | 44 | printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ |
| 30 | "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" | 45 | "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" |
| 31 | url="https://adventofcode.com/$year/day/$daynozero" | ||
| 32 | tmux new-session \; \ | 46 | tmux new-session \; \ |
| 33 | send-keys "$editor" C-m \; \ | 47 | send-keys "$editor" C-m \; \ |
| 34 | split-window -h \; \ | 48 | split-window -h \; \ |
