browser: wget-ifmodified script to download new caniuse data
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 12 Feb 2015 05:11:17 +0000 (06:11 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 13 Feb 2015 16:46:33 +0000 (17:46 +0100)
Makefile
tools/wget-ifmodified [new file with mode: 0755]

index d7c10031a5ae2953ad1540d6b7fff08c04767731..4e517682d9aec975ee67d22a11212672613574cc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,9 @@ data/countryInfo.txt:
 countries.inc.pl: data/countryInfo.txt
        tools/mkcountries-geonames data/countryInfo.txt >$@
 
+data/caniuse.json:
+       tools/wget-ifmodified http://caniuse.com/data.json $@
+
 clean:
        -rm digraphs.inc.pl
        -rm unicode-char.inc.pl
diff --git a/tools/wget-ifmodified b/tools/wget-ifmodified
new file mode 100755 (executable)
index 0000000..bae00f1
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env sh
+
+set -u
+
+if [ -z "$1" ]
+then
+       echo 'Usage: $0 <url> [<target>]' >&2
+       # download url to target location if modified
+       exit 64 # EX_USAGE
+fi
+
+source=$1
+target=${2:-${source##*/}}
+
+if [ -e "$target" ]
+then
+       modified=$(stat -c%y -L "$target") &&
+       modified=$(date -R -d "$modified")
+       echo download since: $modified
+fi
+
+headers=${modified:+If-Modified-Since: $modified}
+wget -nv --header="$headers" -O "$target.new" "$source" &&
+mv "$target.new" "$target" ||
+rm "$target.new" # clean up failed download (usually empty 304 response)
+