Sometimes, you’re testing a chat bot dingus, and you need a couple images so it can respond to @bot boop . I wanted more than 10, quickly, preferably without having to click through Google Image search and manually download them.

Giphy and Imgur both require you to sign up and make an oAuth app and blah blah blah before you can start using their API. Not worth it for a trivial one-off.

Turns out Reddit exposes any endpoint in JSON as well as for web browsers, and that’s publicly accessible. And Reddit has a whole community called /r/BoopableSnoots .

So I threw this command together:

curl "https://www.reddit.com/r/BoopableSnoots.json" | \
jq -c '.data.children | .[].data.url' | \
xargs -n 1 curl -O

What is this doing?

curl - sends a GET request to the specified URL and forwards the response body to stdout .

| - take the output of the previous command on stdout and feed it into the next command as stdin

jq -c '...' - jq is a command-line JSON parser and editor. This command drills one level down the object structure returned by reddit and returns the data.url field. The -c flag removes quoting from the output, and the .[] iterates across an array, outputting one element per line

xargs - is a meta-command; it says “run the following command for each line of input on stdin.” It can run in parallel, or in a pool of workers, etc.

curl -O - sends a GET request to the specified URL and saves the response to the filesystem using the filename contained in the URL

Putting it all together:

  1. Get the ~25 most recent posts off Reddit’s BoopableSnoots community
  2. Filter down to just the images that people posted
  3. download those images to the current directory

This quickly got me some snoots for my bot to boop, and I could move on with my work.