From 469143445f6ef32b7dff34a755f1464068db322b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 22 Nov 2020 18:54:58 +0100 Subject: Add 'blp' tool This script retrieves the phone number associated with a Blocket.se ad. --- Makefile | 4 ++-- blp | 11 +++++++++++ blp.1 | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100755 blp create mode 100644 blp.1 diff --git a/Makefile b/Makefile index 90e7260..d30a1e6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ install: - install blm blq xii /usr/bin/ - install -m 644 blq.1 blm.1 xii.1 /usr/share/man/man1/ + install blm blp blq xii /usr/bin/ + install -m 644 blm.1 blp.1 blq.1 xii.1 /usr/share/man/man1/ install -m 644 mboxu.5 /usr/share/man/man5/ diff --git a/blp b/blp new file mode 100755 index 0000000..8ad30c4 --- /dev/null +++ b/blp @@ -0,0 +1,11 @@ +#!/bin/sh + +sed -n 's/ID: //p' | +while read id +do + # Retrieve authorization token + tok=`curl -s "https://www.blocket.se/annons/a/b/$id" | awk '/id="initialState"/ {getline; print}' | jq -r .authentication.bearerToken` + + # Retrieve phone number + curl -s -H "authorization: Bearer $tok" "https://api.blocket.se/search_bff/v1/content/$id/phone_numbers" | jq -r .phone_number +done diff --git a/blp.1 b/blp.1 new file mode 100644 index 0000000..4901b11 --- /dev/null +++ b/blp.1 @@ -0,0 +1,35 @@ +.Dd $Mdocdate$ +.Dt blp 1 +.Os +. +.Sh NAME +.Nm blp +.Nd retrieve phone numbers for ads +. +.Sh SYNOPSIS +.Nm +. +.Sh DESCIPTION +.Pp +.Nm +retrieves the telephone number attached to Blocket.se ads formatted with +.Xr blm 1 +on standard input. +Specifically, it looks for +.Ql ID +headers. +Any line not containing an +.Ql ID +header is ignored. + +You can pipe a message from +.Xr mailx 1 +into +.Nm +to display the telephone number associated with a given ad. +. +.Sh AUTHORS +.Pp +.Nm +is written by John Ankarström +.Aq Mt john (at) ankarstrom.se . -- cgit v1.2.3