From 3537be9e7c578f8ca84e9d420044654577706a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 22 Nov 2020 18:54:41 +0100 Subject: Add more useful headers --- blm | 18 +++++++++++++++--- blm.1 | 9 +++++++++ blq | 10 ++++++---- blq.1 | 10 ++++++++++ xii | 4 ++-- xii.1 | 10 +++++----- 6 files changed, 47 insertions(+), 14 deletions(-) diff --git a/blm b/blm index f00e254..51bd0e5 100755 --- a/blm +++ b/blm @@ -4,9 +4,21 @@ jq -r '.data[] | "From BLOCKET " + (.list_time | sub("\\+[0-9][0-9]:00$"; "Z") | fromdate | strftime("%a %b %e %T %Y")) + "\n" + - "From: \"" + .advertiser.name + ", " + .location[0].name + " (" + .advertiser.type + ")\" \n" + - "Subject: " + "(" + (.price.value | tostring) + ") " + .subject + "\n" + - ([.images[].url] | map("X-Image: " + . + "?type=original") | join("\n")) + "\n" + +'"$(test "$1" = -d && printf '%s\n' ' + "From: \"" + .advertiser.name + ", " + .location[0].name + "\" \n" + + "Subject: (" + (.price.value | tostring) + ") " + .subject + "\n" + +' || printf '%s\n' ' + "From: \"" + .advertiser.name + "\" \n" + + "Subject: " + .subject + "\n" + +')"' + "ID: " + .ad_id + "\n" + + "Link: " + .share_url + "\n" + + "Price: " + (.price.value | tostring) + " " + .price.suffix + "\n" + + "Type: " + .advertiser.type + "\n" + + ([.category[].name] | map("Category: " + . ) | join("\n")) + "\n" + + ([.location[].name] | map("Location: " + . ) | join("\n")) + "\n" + + "Map: " + .map_url + "\n" + + ([.images[].url] | map("Image: " + . + "?type=original") | join("\n")) + "\n" + "\n" + .body + "\n" + "\n" ' diff --git a/blm.1 b/blm.1 index 32c17b6..0315520 100644 --- a/blm.1 +++ b/blm.1 @@ -11,6 +11,7 @@ translator for . .Sh SYNOPSIS .Nm +.Op Fl d . .Sh DESCIPTION .Pp @@ -21,6 +22,14 @@ received on standard input, into .Xr mboxu 5 . The results can be saved in a file and opened successfully with most mail readers. + +If the +.Fl d +(dumb) flag is present, then the location and price associated with each ad are added to the +.Ql From +and +.Ql Subject +headers, respectively. . .Sh AUTHORS .Pp diff --git a/blq b/blq index 1e91ce9..c740ec2 100755 --- a/blq +++ b/blq @@ -1,6 +1,6 @@ #!/bin/sh -# Perform a search on Blocket.se (API v6, Nov 2020) +# Perform a search on Blocket.se (Nov 2020) usage() { echo usage: $0 query 1>&2; exit 1; } @@ -11,10 +11,12 @@ fi # Parse options r= -while getopts rc o +d= +while getopts dr o do case $o in - r) r=1 ;; # process with blm and read in MAILER + d) d=-d ;; # send -d (dumb) option to blm + r) r=-r ;; # process with blm and read in MAILER ?) usage ;; esac done @@ -32,7 +34,7 @@ curl -s -H "authorization: Bearer $tok" "https://api.blocket.se/search_bff/v1/co { test ! -z "$r" && { f=/tmp/blq.$RANDOM - blm > $f + blm $d > $f eval $MAILER -f $f < /dev/tty rm $f } || cat diff --git a/blq.1 b/blq.1 index 8ddaa3b..a2607c8 100644 --- a/blq.1 +++ b/blq.1 @@ -9,6 +9,7 @@ .Sh SYNOPSIS .Nm .Op Fl r +.Op Fl d .Ar query . .Sh DESCIPTION @@ -39,6 +40,15 @@ and opens the resulting mbox file in or the value of .Ev MAILER . The temporary mbox file is automatically deleted. + +If +.Fl r +is present together with +.Fl d , +.Xr blm 1 +is called with the +.Fl d +flag. . .Sh AUTHORS .Pp diff --git a/xii b/xii index c79e967..fd88276 100755 --- a/xii +++ b/xii @@ -1,6 +1,6 @@ #!/bin/sh -# Download and display X-Image images +# Download and display images referenced in Image headers : ${VIEWER:=fbi} @@ -8,7 +8,7 @@ dir=/tmp/$RANDOM mkdir $dir -sed -n 's/^X-Image: //p' | +sed -n 's/^Image: //p' | while read url do curl "$url" > $dir/$RANDOM diff --git a/xii.1 b/xii.1 index d79b3a9..ffc7a26 100644 --- a/xii.1 +++ b/xii.1 @@ -4,7 +4,7 @@ . .Sh NAME .Nm xii -.Nd X-Image viewer +.Nd download and view images in Image headers . .Sh SYNOPSIS .Nm @@ -13,10 +13,10 @@ .Pp .Nm downloads and views images specified in any number of -.Ql X-Image -headers contained in any number of e-mail messages given on standard input. +.Ql Image +headers contained in any number of mail messages given on standard input. Any line not containing an -.Ql X-Image +.Ql Image header is ignored. This means that you can conveniently pipe messages from @@ -25,7 +25,7 @@ into .Nm to display any referenced remote images. -.Ql X-Image +.Ql Image headers serve as a way of referencing (remote) images in an e-mail message without MIME. They are used in the output of .Xr blm 1 . -- cgit v1.2.3