From 4645874c82b2a5c61c6dda9f6a4b23bfb61e1c61 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 25 Jun 2025 22:30:24 +0300 Subject: [PATCH] Create a script to download the NASA Astronomy Picture of the Day --- .local/bin/get-nasa-apod | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 .local/bin/get-nasa-apod diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod new file mode 100755 index 0000000..08454e8 --- /dev/null +++ b/.local/bin/get-nasa-apod @@ -0,0 +1,34 @@ +#! /usr/bin/bash + +set -euo pipefail +IFS=$'\n\t' + +API_KEY="${NASA_API_KEY:-DEMO_KEY}" +if [ "${API_KEY}" = "DEMO_KEY" ]; then + echo "No API key set! using demo key." +fi + +WALLPAPERS="$(systemd-path user)"/Wallpapers + +mkdir --parents "${WALLPAPERS}" + +APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}" +response="$(curl --silent "${APOD_URL}")" +picture_date="$(printf '%s' "${response}" | jq --raw-output .date)" +picture_url="$(printf '%s' "${response}" | jq --raw-output .hdurl)" + +extension="${picture_url##*.}" +filename="${picture_date}.${extension}" +outfile="${WALLPAPERS}/${filename}" + +curl \ + --location \ + --output "${outfile}" \ + --silent \ + "${picture_url}" +ln \ + --force \ + --symbolic \ + "${outfile}" \ + "${WALLPAPERS}/today.${extension}" +swaymsg reload