Create a script to download the NASA Astronomy Picture of the Day

This commit is contained in:
Ohad Livne 2025-06-25 22:30:24 +03:00
parent 2acc9755e0
commit 4645874c82
Signed by: libohad-dev
GPG key ID: 34FDC68B51191A4D

34
.local/bin/get-nasa-apod Executable file
View file

@ -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