Created
September 26, 2018 02:25
-
-
Save youthlin/bdf3f9751dc5c554031048b383157687 to your computer and use it in GitHub Desktop.
BingWallpaper-xfce4
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
#!/bin/bash | |
#by youthlin.chen https://youthlin.com | |
dir=`pwd` | |
file=`curl -I "https://cn.bing.com/ImageResolution.aspx?w=1920&h=1080" 2>/dev/null | grep Location | awk '{print $2}'` | |
file=${file%_*} | |
file="${file}_1920x1080.jpg" | |
url="https://cn.bing.com$file" | |
file=${file##*/} | |
today=`date +%Y%m%d` | |
file="${today}_${file}" | |
curl $url >$file 2>/dev/null | |
/usr/bin/xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/workspace0/last-image -s $dir/$file | |
/usr/bin/xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor1/workspace0/last-image -s $dir/$file | |
notify-send -i $dir/bing-logo.png '壁纸已设置' $dir/$file | |
#bing-logo.png: http://pluspng.com/img-png/logo-bing-png-bing-icon-1600.png |
KDE 其实还可以 在桌面右键-配置桌面-壁纸-壁纸类型-每日一图-Bing
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/`id -u`/bus
#!/bin/bash
PWD=$(
cd "$(dirname "$0")" || exit
pwd
)
# echo "$PWD"
mkdir -p "${PWD}/1920x1080"
mkdir -p "${PWD}/1080x1920"
# 最多可以获取的图片数量
MAX_COUNT=8
# 使用 curl 获取 json 数据
# curl -s 静默模式,结果是 json 给 python3 处理
json=$(/usr/bin/curl -s "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8")
# 检查每个图片
idx=0
while ((idx < MAX_COUNT)); do
# 使用 python3 的 json 库,解析出图片地址
url=$(echo "$json" | /usr/local/bin/python3 -c "import sys, json; print(json.load(sys.stdin)['images'][${idx}]['url'])")
# url=/th?id=OHR.SailingStone_ROW7078458305_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp
# %% 表示从尾部去掉所有匹配正则的部分,正则 &* 表示符号&后跟着任意字符串
name=${url%%&*}
# 解析出日期
date=$(echo "$json" | /usr/local/bin/python3 -c "import sys, json; print(json.load(sys.stdin)['images'][${idx}]['startdate'])")
# 判断改日期图片是否已下载
if [ ! -e "${PWD}/1920x1080/${date}.jpg" ]; then
# name=/th?id=OHR.SailingStone_ROW7078458305_1920x1080.jpg
# echo "$date $name"
/usr/bin/curl -s -o "${PWD}/1920x1080/${date}.jpg" "https://bing.com$name"
fi
# 判断竖版图片是否存在
if [ ! -e "${PWD}/1080x1920/${date}.jpg" ]; then
# echo "竖版: $date ${name/1920x1080/1080x1920}"
/usr/bin/curl -s -o "${PWD}/1080x1920/${date}.jpg" "https://bing.com${name/1920x1080/1080x1920}"
fi
idx=$((idx + 1))
done
save as ~/Pictures/bing/bing.sh
EDITOR=vim crontab -e
输入并保存:
# Min Hour Day Month Week Cmd
0 8 * * * bash ~/Pictures/bing/bing.sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bing-kde.sh
部件被锁定时不能更改!!
Can NOT set wallpaper when widgets are locked!!!
https://github.com/pashazz/ksetwallpaper/blob/master/ksetwallpaper.py
https://www.reddit.com/r/kde/comments/65pmhj/change_wallpaper_from_terminal/
curl -L 302 http://ju.outofmemory.cn/entry/95924