You are not logged in.
A simple tool to deliver you amazing daily shots of nature and places from Bing. Its made mostly with dwm/i3/bspw users in mind, so it has no scripting, no config files and minimum required libraries. Actually, it needs just curl and json-c, and you probably already have both of them in your system. By default, it uses feh to set the wallpaper, but you can use any other tool via command line argument, so this dependency is optional.
Offline
The install on Arch can be condensed into a single line:
makepkg -i
Offline
#!/bin/bash
erexit() {
echo "$*"
exit
}
[[ " $@ " =~ " force " ]] && rm /tmp/.bingwp.*
offset=0
[[ "$1" =~ [1-9][0-9]*$ ]] && offset=$1
market=${LANG:-en-US}
market=${market%.*}
market=${market/_/-}
read data < <(curl -s "https://www.bing.com/HPImageArchive.aspx?idx=${offset}&n=1&mkt=${market}")
# extract image url
image=${data#*\<url\>}
image=${image%\</url\>*}
# smaller versions
# 1920x1080, 1366x768, 1280x768, 1280x720, 1024x768, 800x600, 640x480
# do we need to update?
read md5 dash < <(md5sum <<< "$image")
set_wallpaper() {
feh --bg-fill "/tmp/.bingwp.$md5"
if type notify-send > /dev/null 2>&1; then
info=${data#*\<copyright\>}
info=${info%\</copyright\>*}
notify-send -u low -t 8000 "New Bing Wallpaper" "$info"
fi
}
if [ -e "/tmp/.bingwp.$md5" ]; then
[[ " $@ " =~ "update" ]] && set_wallpaper
exit
fi
# clean-up
rm /tmp/.bingwp.*
# get & set wallpaper
curl -s "https://www.bing.com/$image" > /tmp/.bingwp.$md5
[ -e "/tmp/.bingwp.$md5" ] || erexit "Failed to obtain https://www.bing.com/$image"
set_wallpaper
Last edited by seth (2021-07-08 22:02:35)
Offline
The install on Arch can be condensed into a single line:
Thanks, fixed.
:tongue:
Cool script!
Well, I was aware from the beginning that the task that simple could be done with a shell script. But being more of a programmer than an admin, I prefer to have some plain old C and one clear line in .xprofile than an noodle bowl of bashisms and arcane symbols of crontab. Also, the script downloads the largest file and the actual sizes I need are 2 and 4 times smaller.
Offline
W/ my programmer hat on, I believe that whenever you call system() you wanted to write a shell script
I checked, but the wallpapers do not seem available in random dimensions (or even just common ones besides maybe the vesa standard) - is this documented somewhere?
Otherwise one could extract the required dimensions from randr (whether asking xrandr in a script or XRRConfigCurrentConfiguration) and if the images are available in better details like 3840x2160 also reasonably use --no-xinerama on multiscreen setups.
Offline
I'm not against shell scripts per se. But for me, when you need specific data manipulation and logic it's better to write a program than a script.
When googled about the API I'd found this list of supported dimensions: 1920x1200, 1920x1080, 1366x768, 1280x768, 1280x720, 1024x768. I have no idea how official or actual this list is, so I didn't added it to the Readme, but I use 1366x768 and 1024x768 on my books.
May be I'll add image size auto-selection in one of the next versions, thnx for the idea.
Offline
From my tests, 640x480 & 800x600 work, but 1920x1200 doesn't (at least not when the default is 1920x1080) - too bad that higher resolutions don't seem available at all.
Offline
Slick, one other thought is allowing one to change markets as depending on the part of the world you load Bing there may be a different picture.
This old python script allowed one to do just that for downloading bing wallpapers.
Last edited by CarbonChauvinist (2021-07-08 16:54:17)
"the wind-blown way, wanna win? don't play"
Offline
allowing one to change markets
Done. Use -m <market> to select one manually or -M to let the program get the value from the LANG variable.
Offline
One thing I noticed when adding this to the script is that the wallpaper seems to change 0:00 local time, so there's probably no need to poll this every 15 minutes and you can just set a realclock timer, https://katastrophos.net/symbian-dev/GU … 299F2.html
Offline
just set a realclock timer
Yeah, that was my first thought. But in my use case there is no guarantee there will be an Internet connection when the timer will fire.
Each check is just a comparison between saved expiration time and current time, quite cheap an operation. So I've decided to trade some overhead with polling for the simplicity of the code.
Offline