Skip to content

Instantly share code, notes, and snippets.

@larryhou
Created January 6, 2017 06:29
Show Gist options
  • Select an option

  • Save larryhou/70aa5c3319760947916a65d6549ceca9 to your computer and use it in GitHub Desktop.

Select an option

Save larryhou/70aa5c3319760947916a65d6549ceca9 to your computer and use it in GitHub Desktop.
Shell tool for downloading all apple latest sample codes automatically
#!/bin/bash
# set -x
JSON='library.json'
export HOME='https://developer.apple.com/library/content'
# curl -s -o ${JSON} ${HOME}/navigation/library.json
function dojob()
{
# echo "$3.date:${1} url:${2}"
location=${HOME}/$(echo ${2} | sed 's/..\///' | awk -F'/Introduction' '{print $1}')
dir=$(echo ${1} | awk -F'-' '{print $1}')
if [ ! -d "${dir}" ]
then
mkdir -pv ${dir}
fi
url=${location}/$(curl -s ${location}/book.json | jq -r '.sampleCode')
wget ${url} -O ${dir}/$(echo ${url} | awk -F'/' '{print $NF}')
}
export -f dojob
cat ${JSON} | jq -r '.documents|map([.[3],.[9]])|map(select(.[2]|contains("samplecode"))|join("|"))|join("\n")' | sort -r | awk -F'|' '{
system("dojob "$1" "$2" "NR)
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment