抓取bing首页图片当壁纸shell脚本
Tofloor
poster avatar
qq420100523
deepin
2018-09-16 22:00
Author
本帖最后由 qq420100523 于 2018-9-16 16:16 编辑
  1. #!/bin/bash
  2. # picture directory
  3. PICTURE_DIR=~/Pictures/bing_wallpapers/
  4. # Create picture directory if it doesn't already exist
  5. mkdir -p "${PICTURE_DIR}"

  6. # Base Bing URL
  7. bing="www.bing.com"

  8. # default index
  9. idx=0

  10. # Max Number of images
  11. n=8

  12. # What day to start from. 0 is the current day,1 the previous day, etc...
  13. day="&idx=$idx"

  14. # Number of images to get
  15. # May change this script later to get more images and rotate between them
  16. number="&n=$n"

  17. #Set market, other options are:
  18. #"&mkt=zh-CN"
  19. #"&mkt=ja-JP"
  20. #"&mkt=en-AU"
  21. #"&mkt=en-UK"
  22. #"&mkt=de-DE"
  23. #"&mkt=en-NZ"
  24. #"&mkt=en-CA"
  25. #"&mkt=en-US"
  26. market="&mkt=zh-CN"

  27. # Parse bing.com and acquire picture URL(s)
  28. # Get the json file
  29. json=$(curl -sL "http://$bing/HPImageArchive.aspx?format=js$day$number$market" )
  30. #echo $json

  31. # urls=$(echo $json | grep -Po '"url":".*?"' | sed "s/\"//g" | awk -F "[:]" '/url/{print$2}')
  32. urls=$(echo $json | grep -Po '"url":".*?"' | sed "s/\"//g" | cut -d : -f 2)
  33. urls=(${urls/// })
  34. # Download the pictures
  35. for img_url in "${urls[@]}"; do
  36.         img_name=$(echo "$img_url"|sed -e "s/.*\/\(.*\)/\1/")
  37.         if [ ! -f "$PICTURE_DIR/$img_name" ]; then
  38.         printf "Downloading: $img_name...\n"
  39.         curl -s -Lo "$PICTURE_DIR/$img_name" "$bing/$img_url"
  40.     else
  41.         printf "Skipping: $img_name...\n"
  42.     fi
  43. done
Copy the Code

改权限运行:
  1. chmod u+x getBingWallpapers.sh
  2. ./getBingWallpapers.sh
Copy the Code
搭配自动切换壁纸shell脚本一起食用,口味更佳!
自动切换壁纸shell脚本:https://bbs.deepin.org/post/168824#=1##pid516428
Reply Favorite View the author
All Replies
avatar
addhapp
deepin
2018-09-16 22:24
#1
给力,收藏了
Reply View the author