Compare commits
1 commit
1b278acd2b
...
0dfd2abfd5
| Author | SHA1 | Date | |
|---|---|---|---|
| 0dfd2abfd5 |
5 changed files with 12 additions and 29 deletions
|
|
@ -1,2 +0,0 @@
|
||||||
GOBIN=/home/ohad/.local/state/go/bin
|
|
||||||
GOPATH=/home/ohad/.cache/go
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Refresh the wallpaper using the NASA Astronomy Picture of the Day
|
Description=Refresh the wallpaper using the NASA Astronomy Picture of the Day
|
||||||
After=network-online.target
|
|
||||||
Wants=get-nasa-apod.timer
|
Wants=get-nasa-apod.timer
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Daily NASA wallpaper fetch
|
Description=Daily NASA wallpaper fetch
|
||||||
After=network-online.target
|
|
||||||
Requires=get-nasa-apod.service
|
Requires=get-nasa-apod.service
|
||||||
|
|
||||||
[Timer]
|
[Timer]
|
||||||
Unit=get-nasa-apod.service
|
Unit=nasa-apod.service
|
||||||
OnCalendar=daily
|
OnCalendar=daily
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|
|
||||||
|
|
@ -8,47 +8,34 @@ if [ "${API_KEY}" = "DEMO_KEY" ]; then
|
||||||
echo "No API key set! using demo key."
|
echo "No API key set! using demo key."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
WALLPAPERS="$(systemd-path user)"/Pictures/nasa
|
WALLPAPERS="$(systemd-path user)"/Wallpapers
|
||||||
|
|
||||||
mkdir --parents "${WALLPAPERS}"
|
mkdir --parents "${WALLPAPERS}"
|
||||||
|
|
||||||
APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}"
|
APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}"
|
||||||
echo "Fetching data from API"
|
response="$(curl --silent "${APOD_URL}")"
|
||||||
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_date="$(printf '%s' "${response}" | jq --raw-output .date)"
|
||||||
picture_url="$(printf '%s' "${response}" | jq --raw-output .hdurl)"
|
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##*.}"
|
extension="${picture_url##*.}"
|
||||||
filename="${picture_date}.${extension}"
|
filename="${picture_date}.${extension}"
|
||||||
outfile="${WALLPAPERS}/${filename}"
|
outfile="${WALLPAPERS}/${filename}"
|
||||||
|
|
||||||
if [ -f "${outfile}" ]; then
|
if [ -f "${outfile}" ]; then
|
||||||
echo "Target file already exists"
|
echo "Target file already exists"
|
||||||
else
|
exit 0
|
||||||
echo "Creating temporary file"
|
fi
|
||||||
|
|
||||||
tempfile="$(mktemp)"
|
tempfile="$(mktemp)"
|
||||||
echo "Fetching the daily picture"
|
|
||||||
curl \
|
curl \
|
||||||
--location \
|
--location \
|
||||||
--output "${tempfile}" \
|
--output "${tempfile}" \
|
||||||
--silent \
|
--silent \
|
||||||
"${picture_url}"
|
"${picture_url}"
|
||||||
echo "Transaction-like file update"
|
|
||||||
mv "${tempfile}" "${outfile}"
|
mv "${tempfile}" "${outfile}"
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Updating the wallpaper image"
|
|
||||||
ln \
|
ln \
|
||||||
--force \
|
--force \
|
||||||
--symbolic \
|
--symbolic \
|
||||||
"${outfile}" \
|
"${outfile}" \
|
||||||
"${WALLPAPERS}/today"
|
"${WALLPAPERS}/today"
|
||||||
echo "Refreshing the desktop background"
|
|
||||||
swaymsg output "*" bg "${SWAY_WALLPAPER}" fill
|
swaymsg output "*" bg "${SWAY_WALLPAPER}" fill
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ recording_filename() {
|
||||||
echo ~/Pictures/screenshots/recording-"$(ts)".mp4
|
echo ~/Pictures/screenshots/recording-"$(ts)".mp4
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -z "${1+exists}" ]; then
|
if [ -z "$1" ]; then
|
||||||
option=$(listopts | fuzzel --dmenu)
|
option=$(listopts | fuzzel --dmenu)
|
||||||
else
|
else
|
||||||
option="$1"
|
option="$1"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue