konachan-wallpaper/updateWallpaper.sh

64 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
tags="scenic order:random width:1600"
picdir=`realpath $(dirname "${BASH_SOURCE[0]}")`
del="30m"
sud=0
for i in "$@"; do
case $i in
-s=*|--start-up-delay=*)
sud="${i#*=}"
shift
;;
-d=*|--delay=*)
del="${i#*=}"
shift
;;
-t=*|--tags=*)
tags="${i#*=}"
shift
;;
-h|--help*)
echo "usage: $0 <options>"
echo "Options:"
echo " -s --start-up-delay=del Set time between start and first image request."
echo " -d --delay=del Set delay between image requests."
echo " -t --tags=tags The actual search string. Special fields allowed."
echo "Notes:"
echo " All times need to be formatted for the sleep command."
exit 1
;;
*)
# Unknown
;;
esac
done
if [ "$sud" != "0" ]; then
sleep "$sud";
fi
tags=`echo -n "$tags" | sed "s/ /%20/g"`
while [ 0 ]; do
json=`curl "http://konachan.com/post.json?tags=$tags&limit=1"`
id=`echo $json | jq -r '.[0].id'`
url=`echo $json | jq -r '.[0].file_url'`
ext=`echo $url | sed "s/.*\.//g"`
local_url="$picdir/$id.$ext"
echo "Updating wallpaper to $id..."
if [ -f "$local_url" ]; then
echo "Already downloaded."
else
echo "Downloading $url..."
curl -o "$local_url" "$url"
fi
gsettings set org.gnome.desktop.background picture-uri "$local_url"
sleep "$del"
done