diff options
author | epoch <epoch@enzo.thebackupbox.net> | 2022-02-01 03:21:34 +0000 |
---|---|---|
committer | epoch <epoch@enzo.thebackupbox.net> | 2022-02-01 03:21:34 +0000 |
commit | da5080c53ce8e9e520187e19eeb907c46607b4f0 (patch) | |
tree | 415adf4e588615f7989b55a91fa512453b07bade | |
parent | 0608408fbc36dae25ab5cc114fb51b622ecc5937 (diff) | |
download | uritools-da5080c53ce8e9e520187e19eeb907c46607b4f0.tar.gz uritools-da5080c53ce8e9e520187e19eeb907c46607b4f0.zip |
wikipedia search handler added and normal handler updated
-rw-r--r-- | contrib/Makefile | 1 | ||||
-rwxr-xr-x | contrib/wikipedia-handler | 7 | ||||
-rwxr-xr-x | contrib/wikipedia-search-handler | 17 |
3 files changed, 23 insertions, 2 deletions
diff --git a/contrib/Makefile b/contrib/Makefile index 53667f6..06b2d9c 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -7,4 +7,5 @@ all: install: install -Dt $(PREFIX)/bin wikipedia-handler + install -Dt $(PREFIX)/bin wikipedia-search-handler install -Dt ~/.config/uristart.conf.d/ wikipedia.uristart.conf diff --git a/contrib/wikipedia-handler b/contrib/wikipedia-handler index 724bda5..c9aaae6 100755 --- a/contrib/wikipedia-handler +++ b/contrib/wikipedia-handler @@ -1,10 +1,13 @@ #!/usr/bin/env bash -xmessage "loading page for: $1" page="$(uriescape "$1")" cache_file=~/.cache/wikipedia/"${page}.pdf" mkdir -p ~/.cache/wikipedia ## follow redirects (-L), silent (-s), and no globbing (-g), you can guess what -H does. last_modified="$(rfc7231date "$(stat -c '%Y' "${cache_file}")")" -curl -H "If-Modified-Since: ${last_modified}" -L -s -g "https://en.wikipedia.org/api/rest_v1/page/pdf/${page}" -o "${cache_file}" +if [ "$last_modified" ];then + curl -H "If-Modified-Since: ${last_modified}" -L -s -g "https://en.wikipedia.org/api/rest_v1/page/pdf/${page}" -o "${cache_file}" +else + curl -L -s -g "https://en.wikipedia.org/api/rest_v1/page/pdf/${page}" -o "${cache_file}" +fi fileuri=file://"${cache_file}" uristart "${fileuri}" diff --git a/contrib/wikipedia-search-handler b/contrib/wikipedia-search-handler new file mode 100755 index 0000000..72f051f --- /dev/null +++ b/contrib/wikipedia-search-handler @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +uri="$1" +shortened="$(unshorten.sh "${uri}")" +if [ "${shortened}" ];then + uri="${shortened}" +fi +shortened="$(unshorten.sh "${uri}")" +if [ "${shortened}" ];then + uri="${shortened}" + uristart "$uri" +else + curl -g "$uri" | grep '^<i>The page "<a href="/w/index' | sed 's|<i>\([^<]\)</i>||g' | tr '<' '\n' \ + | grep ^a \ + | cut '-d"' -f2 \ + | sed 's|^/|https://en.wikipedia.org/|g' \ + | text_uri-list +fi |