summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-11-22 18:54:41 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-11-22 18:54:41 +0100
commit3537be9e7c578f8ca84e9d420044654577706a11 (patch)
tree379184e06cf5907b053bb9ff44d639dedd63a9b4
parent9c9207c0141b816e351c62e659079912367dbeff (diff)
downloadweb-3537be9e7c578f8ca84e9d420044654577706a11.tar.gz
Add more useful headers
-rwxr-xr-xblm18
-rw-r--r--blm.19
-rwxr-xr-xblq10
-rw-r--r--blq.110
-rwxr-xr-xxii4
-rw-r--r--xii.110
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 + ")\" <noreply@localhost>\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 + "\" <noreply@localhost>\n" +
+ "Subject: (" + (.price.value | tostring) + ") " + .subject + "\n" +
+' || printf '%s\n' '
+ "From: \"" + .advertiser.name + "\" <noreply@localhost>\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 .