From 850f917b6aaea6f25bab8860ede290eb66fe958b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 22 Nov 2020 01:30:55 +0100 Subject: blq: Add -r option The -r option processes the search results with blm and opens the mbox file in a given mail reader. --- blq | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'blq') diff --git a/blq b/blq index 0941da8..085136b 100755 --- a/blq +++ b/blq @@ -2,7 +2,24 @@ # Perform a search on Blocket.se (API v6, Nov 2020) -test -z "$1" && { echo usage: $0 query 1>&2; exit 1; } +usage() { echo usage: $0 query 1>&2; exit 1; } + +if which mutt 1>&- +then : ${MAILER:=mutt -e "set folder=."} +else : ${MAILER:=mailx} +fi + +# Parse options +r= +while getopts rc o +do + case $o in + r) r=1 ;; # process with blm and read in MAILER + ?) usage ;; + esac +done +shift $((OPTIND-1)) +test -z "$1" && usage # Format query string q=`printf '%s\n' "$1" | sed 's/ /%20/g'` @@ -11,4 +28,12 @@ q=`printf '%s\n' "$1" | sed 's/ /%20/g'` tok=`curl -s "https://www.blocket.se/annonser/hela_sverige?q=$q" | awk '/id="initialState"/ {getline; print}' | jq -r .authentication.bearerToken` # Retrieve search results -curl -s -H "authorization: Bearer $tok" "https://api.blocket.se/search_bff/v1/content?lim=40&q=$q&st=s&include=all&gl=3&include=extend_with_shipping" +curl -s -H "authorization: Bearer $tok" "https://api.blocket.se/search_bff/v1/content?lim=40&q=$q&st=s&include=all&gl=3&include=extend_with_shipping" | +{ + test ! -z "$r" && { + f=/tmp/blq.$RANDOM + blm > $f + eval $MAILER -f $f < /dev/tty + rm $f + } || cat +} -- cgit v1.2.3