#!/bin/bash# change directory to where the script residesBASEDIR=$(dirname$0)cd"$BASEDIR"# get htmldata=$(curl -s https://www.nationalgeographic.com/photography/photo-of-the-day/)if[-n"$data"]then# get img urlimgurl=$(grep'property="og:image"'<<<"$data")imgurl="$(cut-d"\""-f4<<<$imgurl)"# get image name from canonical link & get publish datename=$(grep'rel="canonical"'<<<"$data")name="$(cut-d"\""-f4<<<$name)"name="$(cut-d"/"-f8<<<$name)"date=$(grep'meta property="gsa_publish_date"'<<<"$data")date="$(cut-d"\""-f4<<<$date)"date=$(echo"$date" | sed's/-//g')file="$date - $name.jpg"# format file nameif[-f"$file"]then
filesize=$(wc-c < "$file")filesize=$(($filesize))# parseIntactualsize="$(curl -s-L-I$imgurl | awk'tolower ($1) ~ /^content-length/ { print $2 }')"actualsize=$(echo$actualsize | sed"s/$(printf'\r')\$//")# remove carriage return on macOS# check file integrity# sometimes the image may partially downloaded because of network interruptif["$filesize"-eq"$actualsize"]then
echo"$(date) - '$file' already downloaded"else
curl -s"$imgurl">"$file"echo"$(date) - image saved as $file"fi
else
curl -s"$imgurl">"$file"echo"$(date) - image saved as $file"fi
else
echo"$(date) - connection failed"fi
说实话,国家地理的图良莠不齐,自然风光的我很喜欢,人文的很多时候我不太能接受作为壁纸使用。
接下来是颇受好评的必应壁纸,就叫 bing.sh 吧,和国家地理的脚本类似:
#!/bin/bash# change directory to where the script resides.BASEDIR=$(dirname$0)cd"$BASEDIR"bing="https://www.bing.com"# the idx parameter determines where to start from. 0 is the current day,xmlURL="https://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=zh-CN"# Valid options: "_1024x768" "_1280x720" "_1366x768" "_1920x1200" "_1920x1080" "_UHD"picRes="_UHD"# The file extension for the Bing picpicExt=".jpg"# the XML data retrieved from xmlURL, form the fully qualified# URL for the pic of the day, and store it in $picURLdata=$(curl -s$xmlURL)if[-n"$data"]then
picURL=$(cut-d'>'-f13<<<"$data")picURL=$(cut-d'<'-f 1 <<<"$picURL")picURL=$bing$picURL$picRes$picExtdate=$(cut-d'>'-f5<<<"$data")date=$(cut-d'<'-f1<<<"$date")name=$(cut-d'>'-f15<<<"$data")name=$(cut-d'<'-f 1 <<<"$name")name=$(cut-d'('-f 1 <<<"$name")len=${#name}file="$date - ${name:0:len-1}$picExt"if[-f"$file"]then
filesize=$(wc-c < "$file")filesize=$(($filesize))# parseIntactualsize="$(curl -s-L-I$picURL | awk'tolower ($1) ~ /^content-length/ { print $2 }')"actualsize=$(echo$actualsize | sed"s/$(printf'\r')\$//")# remove carriage return on macOSif["$filesize"-eq"$actualsize"]then
echo"$(date) - '$file' already downloaded"else
curl -s"$picURL">"$file"echo"$(date) - image saved as $file"fi
else
curl -s"$picURL">"$file"echo"$(date) - image saved as $file"fi
else
echo"$(date) - connection failed"fi
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plistversion="1.0"><dict><!-- give a unique Label --><key>Label</key><string>com.frankindev.wallpapers.plist</string><!-- path to the script --><key>ProgramArguments</key><array><string>/Users/franklin/Pictures/Wallpapers/wallpapers.sh</string></array><!-- set the interval time in seconds --><key>KeepAlive</key><true/><key>ThrottleInterval</key><integer>7200</integer><!-- std output --><key>StandardOutPath</key><string>/Users/franklin/Pictures/Wallpapers/wallpapers.log</string><!-- std err output --><key>StandardErrorPath</key><string>/Users/franklin/Pictures/Wallpapers/wallpapers.err</string></dict></plist>
如果不指定文件路径,直接运行 Set wallpaper to -> Contents of URL, 它也会下载文件到 Pictures 下,但是每次下载都会在文件名后添加 -1、-2 后缀,浪费空间了~
以上,有什么建议、意见留言讨论哈!
终
Ads by Google
林宏
Frank Lin
Hey, there! This is Frank Lin (@flinhong), one of the 1.41 billion . This 'inDev. Journal' site holds the exploration of my quirky thoughts and random adventures through life. Hope you enjoy reading and perusing my posts.
A shell script to automate the process of downloading National Geographic Photo of the Day. The script saves the image of Photo of the Day in the same directory where the script itself resides. You can use cron to make it automatically running everyday.
IKEv2, or Internet Key Exchange v2, is a protocol that allows for direct IPSec tunnelling between networks. It is developed by Microsoft and Cisco (primarily) for mobile users, and introduced as an updated version of IKEv1 in 2005. The IKEv2 MOBIKE (Mobility and Multihoming) protocol allows the client to main secure connection despite network switches, such as when leaving a WiFi area for a mobile data area. IKEv2 works on most platforms, and natively supported on some platforms (OS X 10.11+, iOS 9.1+, and Windows 10) with no additional applications necessary.
Liquid is a simple template language that Jekyll uses to process pages for your site. With Liquid you can output complex contents without additional plugins.