summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2015-05-21 10:52:38 +0100
committerNick White <git@njw.name>2015-05-21 10:52:38 +0100
commited3f5476c718ff469211a4b73751c32677caa1b4 (patch)
tree717632827a76247750250fe1a99c4b8f5d8db5c2
parent30bf88270dde2bdfefc50e707a718b54876b7e2e (diff)
downloadtkread-ed3f5476c718ff469211a4b73751c32677caa1b4.tar.bz2
tkread-ed3f5476c718ff469211a4b73751c32677caa1b4.zip
Add wrapper scripts to download images as appropriate for displaying webpages
-rwxr-xr-xpull-images17
-rwxr-xr-xread-webpage-with-images14
2 files changed, 31 insertions, 0 deletions
diff --git a/pull-images b/pull-images
new file mode 100755
index 0000000..57ed567
--- /dev/null
+++ b/pull-images
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+usage="Usage: $0 filename [urlroot]"
+
+test $# -eq 0 && echo "$usage" && exit 1
+test $# -gt 2 && echo "$usage" && exit 1
+
+imgurls=`cat "$1" \
+| awk -F \( '/!\[[^\]]*\]\([^\)]*\)/ {print $2}' \
+| sed 's/)\]$//' \
+| awk '{print $1}'`
+
+for i in $imgurls; do
+ echo "$i" | grep -q '//'
+ test $? -ne 0 && i="${2}${i}"
+ wget "$i"
+done
diff --git a/read-webpage-with-images b/read-webpage-with-images
new file mode 100755
index 0000000..b6206d7
--- /dev/null
+++ b/read-webpage-with-images
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+usage="Usage: $0 url"
+
+test $# -ne 1 && echo "$usage" && exit 1
+
+t=`mktemp -d` || exit 1
+cd "$t"
+f=`basename "$1"`
+d=`dirname "$1"`
+curl -L -s -S "$1" | iconv -t utf-8//ignore | pandoc --no-wrap -f html -t markdown > "$f"
+pull-images "$f" "$d"
+tkread -m < "$f"
+rm -rf "$t"