Skip to content

Instantly share code, notes, and snippets.

@neerajvashistha
Last active May 15, 2016 17:04
Show Gist options
  • Save neerajvashistha/1df62e912bb437ee06651d188c2a0f56 to your computer and use it in GitHub Desktop.
Save neerajvashistha/1df62e912bb437ee06651d188c2a0f56 to your computer and use it in GitHub Desktop.
A simple script to change wallpapers
#######settings##########
#select which site to download from
wallhaven=0
imgur=1
#seclect term/blog to search.
wallhavenSearchTerm=Minimalist
imgurSearchBlog=aGWwf
#set purity level
purityLevel=110
#set wallpaper change and download time
wallpaperTimeChange=120 #sec
downloadTimeChange=600 #sec
###donot edit###
count=0
sleep 120
while [ true ]; do
export DISPLAY=:0.0
if [ $(expr $count % $wallpaperTimeChange) -eq 0 ]; then
DIR="/home/cipher/exp/wallpaper"
PIC=$(ls $DIR/* | shuf -n1 >> prevWall.txt; tail -1 prevWall.txt)
gsettings set org.gnome.desktop.background picture-uri "file://$PIC"
fi
if ! wget --spider https://www.google.co.in/; then
notify-send --urgency=low -t 6000 -i face-sad "Internet Status" "You are not connected to Internet"
sleep 300
else
#notify-send --urgency=low -t 6000 -i face-glasses "Internet Status" "You are connected to Internet"
if [ $(expr $count % $downloadTimeChange) -eq 0 ]; then
if [ $wallhaven -eq 1 ]; then
if [ $(expr $count % $(($downloadTimeChange * 5))) -eq 0 ]; then # * 5 time to update the curled html
rm *.html
i=$(shuf -i 1-100 -n 1)
curl -s -L 'http://alpha.wallhaven.cc/search?q='$wallhavenSearchTerm'&categories=100&purity='$purityLevel'&sorting=relevance&order=desc&page='$i -o $i.html
#echo 'curled'
fi
h=$(grep -oPh [0-9]{$(shuf -i 5-6 -n 1)}.jpg $i.html | shuf -n 1)
wget --timeout 10 -nc -c -q -P $DIR http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-$h
#echo 'downloaded'
fi
if [ $imgur -eq 1 ]; then
if [ $(expr $count % $(($downloadTimeChange * 100))) -eq 0 ]; then # * 100 time to update the curled html
rm *.html
curl -s -L 'http://imgur.com/a/'$imgurSearchBlog'/layout/blog' -o $imgurSearchBlog.html
#echo 'curled'
fi
h=$(grep -oPh '<div id=".*" class="post' $imgurSearchBlog.html | cut -d '=' -f 2 | cut -d '"' -f 2 | shuf -n 1)
wget --timeout 10 -nc -c -q -P $DIR 'http://i.imgur.com/'$h'.jpg'
#echo 'downloaded'
fi
fi
fi
if [ $(expr $count % 1800) -eq 0 ]; then
notify-send --urgency=low -t 6000 -i face-wink "Busy huh?" "$(fortune)"
fi
count=$(expr $count + 1)
sleep 1
done
# for previous wallpaper
# gsettings set org.gnome.desktop.background picture-uri "file://$(tail -2 /home/cipher/exp/prevWall.txt | head -1)"
# for next wallpaper
# gsettings set org.gnome.desktop.background picture-uri "file://$(ls /home/cipher/exp/wallpaper/* | shuf -n1 >> prevWall.txt; tail -1 prevWall.txt)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment