Last active
January 24, 2017 11:54
-
-
Save mleczakm/1c54fe245e15ddf936dab628e2c445ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#Market options: en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ | |
#Resolution options: 1366×768, 1920×1080, 1920×1200 | |
Market="en-US" | |
Resolution="1920x1200" | |
Directory="/home/$USER/Pictures/Bing Wallpaper" | |
FileName="background.jpg" | |
ArchiveAmount=31 | |
while ! ping -c 1 bing.com > /dev/null 2>&1; do | |
echo -e "\x1B[93m Waiting for internet connectivity to continue... \x1b[0m" | |
sleep 10; | |
done; | |
mkdir -pv "$Directory" | |
mkdir -pv "$Directory/../Bing Wallpapers Archive" | |
URL=($(curl -s 'http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt='"$Market" | sed -e 's/^.*"urlbase":"\([^"]*\)".*$/\1/')) | |
ImageURL="http://www.bing.com"/$URL"_"$Resolution".jpg" | |
if [ -e "$Directory/$FileName" ] | |
then | |
fileDate=($(date -r "$Directory/$FileName" +"%Y%m%d")) | |
todayDate=($(date +"%Y%m%d")) | |
if [ $todayDate = $fileDate ] | |
then | |
echo -e "\x1B[32m You already have today's Bing image \x1b[0m"; | |
else | |
echo -e "\x1B[32m Downloading Bing again image to: $Directory \x1b[0m"; | |
mv "$Directory/$FileName" "$Directory/../Bing Wallpapers Archive/$(date +"%Y-%m-%d").jpg"; | |
curl -so "$Directory/$FileName" "$ImageURL"; | |
fi | |
else | |
echo -e "\x1B[32m Downloading first Bing image to: $Directory \x1b[0m" | |
curl -so "$Directory/$FileName" "$ImageURL" | |
fi | |
while [ ! -f "$Directory/$FileName" ] | |
do | |
echo -e "\x1B[93m Waiting for Bing image to finish downloading... \x1b[0m" | |
sleep 10 | |
done; | |
cd "$Directory/../Bing Wallpapers Archive" | |
ls -t | tail -n +$((++ArchiveAmount)) | xargs -I {} rm {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment