Skip to content

Instantly share code, notes, and snippets.

@youthlin
Created September 26, 2018 02:25
Show Gist options
  • Save youthlin/bdf3f9751dc5c554031048b383157687 to your computer and use it in GitHub Desktop.
Save youthlin/bdf3f9751dc5c554031048b383157687 to your computer and use it in GitHub Desktop.
BingWallpaper-xfce4
#!/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
@youthlin
Copy link
Author

KDE 其实还可以 在桌面右键-配置桌面-壁纸-壁纸类型-每日一图-Bing

@youthlin
Copy link
Author

youthlin commented Oct 17, 2018

export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/`id -u`/bus

@youthlin
Copy link
Author

youthlin commented Aug 28, 2020

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

https://youthlin.com/wallpaper#comment-2152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment