software/hoardy-web/./tool/script/hoardy-web-view-w3m

Passively capture, archive, and hoard your web browsing history, including the contents of the pages you visit, for later offline viewing, mirroring, and/or indexing. Your own personal private Wayback Machine that can also archive HTTP POST requests and responses, as well as most other HTTP-level data.

Files

Raw Source

Contents

#!/usr/bin/env bash
set -e

usage() {
    cat << EOF
usage: $0 [--help] WRR_FILE

Generate a plain text preview of a WRR file containing an HTML document using \`w3m\`.

# Options:

  --help                print this message and exit

  --raw-url             print the raw URL stored in the WRR_FILE
  --net-url             format the URL using on-the-wire representation
  --pretty-url          format the URL prettily; default
  --normalized-url      normalize the URL removing empty query parameters, and then format the URL prettily

# Example:

  $0 path/to/wrr/file/containing/html.wrr
EOF
}

kind=pretty_url
while (($# > 0)); do
    case "$1" in
    --help) usage; exit 0 ;;
    --raw-url) kind=raw_url ;;
    --net-url) kind=net_url ;;
    --pretty-url) kind=pretty_url ;;
    --normalized-url) kind=pretty_nurl ;;
    *) break ;;
    esac
    shift
done

(($# > 0)) || { echo "error: need a WRR_FILE"; echo; usage; exit 1; } >&2

trap '[[ -n "$tmp" ]] && rm -f "$tmp"' 0
tmp=$(mktemp hoardy-web-view-w3m.XXXXXXXX.html)

hoardy-web get -l \
        -e "$kind|add_prefix '# url: '" \
        --expr-fd 3 \
        -e "response.body|eb" \
        -- "$1" 3> "$tmp"
echo
w3m -T text/html -dump "$tmp"