Compare commits
9 commits
0dfd2abfd5
...
1b278acd2b
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b278acd2b | |||
| 18ab3487f5 | |||
| c352ad925c | |||
| ec2016c6d1 | |||
| 277b60c13e | |||
| b0ad274461 | |||
| 777b88a37f | |||
| a804440f01 | |||
| fd81499c83 |
5 changed files with 29 additions and 12 deletions
2
.config/go/env
Normal file
2
.config/go/env
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
GOBIN=/home/ohad/.local/state/go/bin
|
||||
GOPATH=/home/ohad/.cache/go
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
[Unit]
|
||||
Description=Refresh the wallpaper using the NASA Astronomy Picture of the Day
|
||||
After=network-online.target
|
||||
Wants=get-nasa-apod.timer
|
||||
|
||||
[Service]
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
[Unit]
|
||||
Description=Daily NASA wallpaper fetch
|
||||
After=network-online.target
|
||||
Requires=get-nasa-apod.service
|
||||
|
||||
[Timer]
|
||||
Unit=nasa-apod.service
|
||||
Unit=get-nasa-apod.service
|
||||
OnCalendar=daily
|
||||
|
||||
[Install]
|
||||
|
|
|
|||
|
|
@ -8,34 +8,47 @@ if [ "${API_KEY}" = "DEMO_KEY" ]; then
|
|||
echo "No API key set! using demo key."
|
||||
fi
|
||||
|
||||
WALLPAPERS="$(systemd-path user)"/Wallpapers
|
||||
WALLPAPERS="$(systemd-path user)"/Pictures/nasa
|
||||
|
||||
mkdir --parents "${WALLPAPERS}"
|
||||
|
||||
APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}"
|
||||
response="$(curl --silent "${APOD_URL}")"
|
||||
echo "Fetching data from API"
|
||||
response="$(curl --silent --write-out '{"rate-limit": %header{x-ratelimit-remaining}}' "${APOD_URL}" | jq --slurp add)"
|
||||
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)"
|
||||
rate_remaining="$(printf '%s' "${response}" | jq '."rate-limit"')"
|
||||
echo "Remaining requests until rate limit: ${rate_remaining}"
|
||||
|
||||
echo "Generating output filename"
|
||||
extension="${picture_url##*.}"
|
||||
filename="${picture_date}.${extension}"
|
||||
outfile="${WALLPAPERS}/${filename}"
|
||||
|
||||
if [ -f "${outfile}" ]; then
|
||||
echo "Target file already exists"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
tempfile="$(mktemp)"
|
||||
curl \
|
||||
else
|
||||
echo "Creating temporary file"
|
||||
tempfile="$(mktemp)"
|
||||
echo "Fetching the daily picture"
|
||||
curl \
|
||||
--location \
|
||||
--output "${tempfile}" \
|
||||
--silent \
|
||||
"${picture_url}"
|
||||
mv "${tempfile}" "${outfile}"
|
||||
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
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ recording_filename() {
|
|||
echo ~/Pictures/screenshots/recording-"$(ts)".mp4
|
||||
}
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
if [ -z "${1+exists}" ]; then
|
||||
option=$(listopts | fuzzel --dmenu)
|
||||
else
|
||||
option="$1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue