Last active
December 17, 2018 08:08
-
-
Save tsmsogn/4c6e2a32360a87844f266ebbbc822570 to your computer and use it in GitHub Desktop.
Fetch and cache the data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
cd $(dirname $0) | |
base=$(pwd) | |
url='' # INPUT URL | |
tmp_file=`date +%s`_shop.json # INPUT TEMPORARY FILE NAME | |
dest='shop.json' # INPUT OUTPUT FILE NAME | |
assert_same() { | |
if [ "$1" = "$2" ]; then | |
return 0; | |
fi | |
return 1 | |
} | |
fetch() { | |
curl_out=`curl -s -k -w "%{http_code}" -o $tmp_file $url` | |
http_code=`echo "$curl_out" | cut -f1` | |
return 0 | |
} | |
main() { | |
debug=false | |
args="" | |
local argc=0 | |
local argv=() | |
while [ $# -gt 0 ]; do | |
case $1 in | |
--debug) | |
debug=true | |
;; | |
esac | |
shift | |
done | |
fetch | |
if $debug; then | |
echo "url: $url" | |
echo "tmp_file: $tmp_file" | |
echo "dest: $dest" | |
echo "http_code: $http_code" | |
fi | |
assert_same 200 $http_code && cp $tmp_file $dest && rm $tmp_file && exit 0 | |
exit 1 | |
} | |
main $* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment