aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-11-29 14:52:27 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-11-29 14:55:03 +0100
commit5c6a17174f6675d01bf35999b025c0e99297a844 (patch)
tree3671a8f8a9b60d46386247a8a291fb6ab388e4a8 /src
parenta4d6defa1722d52bf0f5bb2f3abf1443c4b6509c (diff)
downloadsebastiano.tronto.net-5c6a17174f6675d01bf35999b025c0e99297a844.tar.gz
sebastiano.tronto.net-5c6a17174f6675d01bf35999b025c0e99297a844.zip
Blog post
Diffstat (limited to 'src')
-rw-r--r--src/blog/2025-11-29-aoc-download/aoc-download.md88
-rw-r--r--src/blog/2025-11-29-aoc-download/cookie.pngbin0 -> 76516 bytes
2 files changed, 88 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
new file mode 100644
index 0000000..5190aa9
--- /dev/null
+++ b/src/blog/2025-11-29-aoc-download/aoc-download.md
@@ -0,0 +1,88 @@
1# Downloading AoC puzzle inputs with curl
2
3As in the [past couple of years](../2023-12-25-advent-of-code), soon
4I am going to take part in the daily programming challenges of the
5[Advent of Code](https://adventofcode.com). This time I decided to take
6some time and optimize my working setup a little bit - not that it matters
7for someone solving the problems at my speed.
8
9So let me show you how I automated downloading the inputs for the puzzles
10(which require you to login) using [curl](https://curl.se).
11
12## The problem
13
14In case you are not familiar with the Advent of Code, it is a casual
15programming challenge that takes place every year in December. Every day
16a new problem is released, and you are supposed to write a program that
17solves it and submit your answer as a short string, usually a number.
18The fastest you solve the problems, the more internet points
19you get, and you can brag about it with your colleagues.
20
21The input data for each problem is given as a simple text file. Not
22everyone gets the same, there are a few (hundreds? thousands? not sure)
23of different inputs, and each user is assigned one.
24
25This means that one must log in to be able to download their puzzle input.
26To manually download the input file is quite tedious, so it would be nice
27if there was a way to automate this. Of course,
28[I am](https://github.polettix.it/ETOOBUSY/2022/11/28/aoc-inputs-downloader)
29[not](https://packagist.org/packages/colinodell/aoc-downloader)
30[the](https://github.com/johlinco/aoc-cli)
31[first](https://github.com/Gronner/aoc-downloader)
32[to](https://github.com/czyber/aoc-downloader)
33[think](https://github.com/martintc/aoc-downloader-rs)
34[about](https://github.com/scarvalhojr/aoc-cli)
35[doing](https://github.com/colinodell/aoc-downloader)
36[this](https://github.com/GreenLightning/advent-of-code-downloader).
37
38## Session cookies
39
40If log in was not required, we could simply download the input file for,
41say, day 12 of 2024 and save it to `input.txt` with curl like this:
42
43```
44$ curl https://adventofcode.com/2024/day/12/input -o input.txt
45```
46
47But if you run this command, you'll get something like this:
48
49```
50Puzzle inputs differ by user. Please log in to get your puzzle input.
51```
52
53To make curl act as if we were logged in, we need a
54[session cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies).
55If you log into [adventofcode.com](https://adventofcode.com) on a browser such
56as Firefox, you can right-click on the page, select "Inspect" and then navigate
57to Storage and then Cookies.
58
59![Screenshot of Firefox](./cookie.png)
60
61The long alphanumerical string under "Value" is your session cookie. Anyone
62who gets a hold of it can pretend to be you on this website - by the way,
63this is how the famous YouTube channel
64[Linus tech tips got hacked](https://www.youtube.com/watch?v=yGXaAWbzl5A)
65a couple of years ago.
66
67Save this cookie somewhere, for example in an
68[environment variable](https://en.wikipedia.org/wiki/Environment_variable)
69called `AOC_SESSION_COOKIE`. Then run your curl with an extra option, like so:
70
71```
72$ curl https://adventofcode.com/2024/day/12/input -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt
73```
74
75And you are good to go!
76
77## The fancy script
78
79Typing out the full command above may look cooler than downloading the file
80by right-clicking "Save page as", but it is just as annoying. So obviously I
81saved that command to
82[a script](https://git.tronto.net/scripts/file/aoc.html)
83that also detects the correct file to download based on the current date
84(or on two optional parameters for the year and the day). My script also
85opens up an editor and [Lynx](https://en.wikipedia.org/wiki/Lynx_(web_browser))
86session to set me up to speed, but that is not as interesting.
87
88Happy coding!
diff --git a/src/blog/2025-11-29-aoc-download/cookie.png b/src/blog/2025-11-29-aoc-download/cookie.png
new file mode 100644
index 0000000..947742f
--- /dev/null
+++ b/src/blog/2025-11-29-aoc-download/cookie.png
Binary files differ

Generated with cgit - Back to sebastiano.tronto.net