Create a script to download the NASA Astronomy Picture of the Day
This commit is contained in:
parent
2acc9755e0
commit
4645874c82
1 changed files with 34 additions and 0 deletions
34
.local/bin/get-nasa-apod
Executable file
34
.local/bin/get-nasa-apod
Executable 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue