konachan-wallpaper/updateWallpaper.sh

64 lines
1.3 KiB
Bash
Raw Normal View History

2016-09-11 16:31:50 +02:00
#!/bin/bash
2016-09-13 18:50:19 +02:00
tags="scenic order:random width:1600"
2016-09-11 16:31:50 +02:00
picdir=`realpath $(dirname "${BASH_SOURCE[0]}")`
2016-09-13 18:50:19 +02:00
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"`
2016-09-11 16:31:50 +02:00
while [ 0 ]; do
2016-09-13 18:50:19 +02:00
json=`curl "http://konachan.com/post.json?tags=$tags&limit=1"`
2016-09-11 16:31:50 +02:00
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"
2016-09-13 18:50:19 +02:00
echo "Updating wallpaper to $id..."
2016-09-11 16:31:50 +02:00
if [ -f "$local_url" ]; then
2016-09-13 18:50:19 +02:00
echo "Already downloaded."
2016-09-11 16:31:50 +02:00
else
2016-09-13 18:50:19 +02:00
echo "Downloading $url..."
2016-09-11 16:31:50 +02:00
curl -o "$local_url" "$url"
fi
gsettings set org.gnome.desktop.background picture-uri "$local_url"
2016-09-13 18:50:19 +02:00
sleep "$del"
2016-09-11 16:31:50 +02:00
done