diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-01 19:04:36 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-01 19:04:36 +0100 |
| commit | 55c0e82f420c54eb3766bc9830daf966ba6e68f7 (patch) | |
| tree | a3bb098eea76f66934f0ac8f58b1db2837572534 /src | |
| parent | 5c6a17174f6675d01bf35999b025c0e99297a844 (diff) | |
| download | sebastiano.tronto.net-55c0e82f420c54eb3766bc9830daf966ba6e68f7.tar.gz sebastiano.tronto.net-55c0e82f420c54eb3766bc9830daf966ba6e68f7.zip | |
Update to blog post
Diffstat (limited to 'src')
| -rw-r--r-- | src/blog/2025-11-29-aoc-download/aoc-download.md | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/blog/2025-11-29-aoc-download/aoc-download.md b/src/blog/2025-11-29-aoc-download/aoc-download.md index 5190aa9..a563955 100644 --- a/src/blog/2025-11-29-aoc-download/aoc-download.md +++ b/src/blog/2025-11-29-aoc-download/aoc-download.md | |||
| @@ -86,3 +86,28 @@ opens up an editor and [Lynx](https://en.wikipedia.org/wiki/Lynx_(web_browser)) | |||
| 86 | session to set me up to speed, but that is not as interesting. | 86 | session to set me up to speed, but that is not as interesting. |
| 87 | 87 | ||
| 88 | Happy coding! | 88 | Happy coding! |
| 89 | |||
| 90 | ### Update 2025-12-01 | ||
| 91 | |||
| 92 | An interesting addition to my script: now it can also download and save | ||
| 93 | the `<code>` blocks and save them each in a separate file. This can | ||
| 94 | be useful because these blocks contain example input whose solution is | ||
| 95 | provided in the problem's page. The relevant code snippet, based on | ||
| 96 | `curl` and `sed`, is this: | ||
| 97 | |||
| 98 | ``` | ||
| 99 | url="https://adventofcode.com/$year/day/$daynozero" | ||
| 100 | curl "$url" | sed -n '/<pre><code>/,/<\/code><\/pre>/ p' | (\ | ||
| 101 | i=1 | ||
| 102 | rm -f "code-$i.txt" | ||
| 103 | while read line; do | ||
| 104 | if [ "$line" = "</code></pre>" ]; then | ||
| 105 | i=$((i + 1)) | ||
| 106 | rm -f "code-$i.txt" | ||
| 107 | else | ||
| 108 | echo "$line" | sed 's/<.*>//g' >> "code-$i.txt" | ||
| 109 | fi | ||
| 110 | done | ||
| 111 | ) | ||
| 112 | ``` | ||
| 113 | |||
