You are not logged in.

#1 2021-07-07 16:13:24

archpony
Member
Registered: 2016-05-18
Posts: 7
Website

ponywall: use daily Bing wallpaper with your favourite WM

GitHub page

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

#2 2021-07-08 06:39:19

willemw
Member
Registered: 2013-02-19
Posts: 113

Re: ponywall: use daily Bing wallpaper with your favourite WM

The install on Arch can be condensed into a single line:

makepkg -i

Offline

#3 2021-07-08 08:01:13

seth
Member
Registered: 2012-09-03
Posts: 49,972

Re: ponywall: use daily Bing wallpaper with your favourite WM

#!/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

tongue

Last edited by seth (2021-07-08 22:02:35)

Online

#4 2021-07-08 09:57:44

archpony
Member
Registered: 2016-05-18
Posts: 7
Website

Re: ponywall: use daily Bing wallpaper with your favourite WM

willemw wrote:

The install on Arch can be condensed into a single line:

Thanks, fixed.



willemw wrote:

: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

#5 2021-07-08 12:41:18

seth
Member
Registered: 2012-09-03
Posts: 49,972

Re: ponywall: use daily Bing wallpaper with your favourite WM

W/ my programmer hat on, I believe that whenever you call system() you wanted to write a shell script tongue

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.

Online

#6 2021-07-08 13:29:51

archpony
Member
Registered: 2016-05-18
Posts: 7
Website

Re: ponywall: use daily Bing wallpaper with your favourite WM

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

#7 2021-07-08 13:53:15

seth
Member
Registered: 2012-09-03
Posts: 49,972

Re: ponywall: use daily Bing wallpaper with your favourite WM

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.

Online

#8 2021-07-08 16:50:19

CarbonChauvinist
Member
Registered: 2012-06-16
Posts: 412
Website

Re: ponywall: use daily Bing wallpaper with your favourite WM

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

#9 2021-07-09 08:39:46

archpony
Member
Registered: 2016-05-18
Posts: 7
Website

Re: ponywall: use daily Bing wallpaper with your favourite WM

CarbonChauvinist wrote:

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

#10 2021-07-09 13:34:34

seth
Member
Registered: 2012-09-03
Posts: 49,972

Re: ponywall: use daily Bing wallpaper with your favourite WM

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

Online

#11 2021-07-10 11:45:33

archpony
Member
Registered: 2016-05-18
Posts: 7
Website

Re: ponywall: use daily Bing wallpaper with your favourite WM

seth wrote:

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

Board footer

Powered by FluxBB