From c352ad925ca81d6c3e5b78e01e90920bfdda125f Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Fri, 18 Jul 2025 17:02:33 +0300 Subject: [PATCH] Add logging to the NASA APOD download script --- .local/bin/get-nasa-apod | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index bd69600..e6f91b2 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -13,10 +13,16 @@ WALLPAPERS="$(systemd-path user)"/Pictures/nasa mkdir --parents "${WALLPAPERS}" APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}" +echo "Fetching data from API" response="$(curl --silent "${APOD_URL}")" +echo "Received response from API" +# shellcheck disable=SC2005 +echo "$(printf '%s' "${response}" | jq '.')" +echo "Parsing data" picture_date="$(printf '%s' "${response}" | jq --raw-output .date)" picture_url="$(printf '%s' "${response}" | jq --raw-output .hdurl)" +echo "Generating output filename" extension="${picture_url##*.}" filename="${picture_date}.${extension}" outfile="${WALLPAPERS}/${filename}" @@ -24,18 +30,23 @@ outfile="${WALLPAPERS}/${filename}" if [ -f "${outfile}" ]; then echo "Target file already exists" else + echo "Creating temporary file" tempfile="$(mktemp)" + echo "Fetching the daily picture" curl \ --location \ --output "${tempfile}" \ --silent \ "${picture_url}" + echo "Transaction-like file update" mv "${tempfile}" "${outfile}" fi +echo "Updating the wallpaper image" ln \ --force \ --symbolic \ "${outfile}" \ "${WALLPAPERS}/today" +echo "Refreshing the desktop background" swaymsg output "*" bg "${SWAY_WALLPAPER}" fill