Skip to content

Instantly share code, notes, and snippets.

@palemoky
Created July 8, 2020 05:05
Show Gist options
  • Save palemoky/d44645b49f2d9b8064845d7695e9cebf to your computer and use it in GitHub Desktop.
Save palemoky/d44645b49f2d9b8064845d7695e9cebf to your computer and use it in GitHub Desktop.
Get bing wallpaper via proxy
#!/bin/bash
# Author: Palemoky
# Change directory to work path
cd /path/to/work
pages=$(curl -sG --data-urlencode "country=美国" 'https://ip.jiangxianli.com/api/proxy_ips' | jq .data.last_page)
for page in $(eval echo {1..${pages}}); do
# Get proxy IP
ip_list=$(curl -sG --data-urlencode "country=美国" --data-urlencode "country="$page 'https://ip.jiangxianli.com/api/proxy_ips?order_by=validated_at&order_rule=desc' | jq .data.data)
for index in {0..14}; do
# No valid IP to exit
ip=$(jq .[$index].ip <<<$ip_list)
if [ 'null' == $ip ]; then
wget -q --output-document=/dev/null 'https://sc.ftqq.com/xxx.send?text=US-Bing-Wallpaper&desp=No%20valid%20IP%20available'
exit 1
fi
proxy=$ip':'$(jq .[$index].port <<<$ip_list)
proxy=${proxy//\"/}
# check=$(curl --connect-timeout 3 -sx $proxy 'myip.ipip.net' 2>&1)
# if [[ $? -ne 0 ]] || [[ ! $check =~ '美国' ]]; then
# continue;
# fi
# Fetch image
img=$(curl --connect-timeout 10 -sx $proxy 'http://bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&pid=hp&FORM=BEHPTB&video=1' 2>&1)
# Change IP when timeout
if [ $? -ne 0 ]; then
continue
fi
img_path=$(jq .images[0].url <<<$img)
if [[ ! $img_path =~ 'EN-US' ]]; then
continue
fi
img_name=$(jq .images[0].urlbase <<<$img)
img_name=${img_name#*=}
filename=${img_name//\"/}.jpg
# Save image
curl -so $filename https://bing.com${img_path//\"/}
# Extracting copyright information
copyright=$(jq .images[0].copyright <<<$img)
copyright=${copyright//\"/}
# Todo something ...
exit 0
done
exit 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment