summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-11-21 16:01:04 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-11-21 16:02:49 +0100
commitae40d5204ae0d751d17497cba532e5f428aa5747 (patch)
tree9d974e0800b2555a204d9b28640113e2eba011ac
downloadweb-ae40d5204ae0d751d17497cba532e5f428aa5747.tar.gz
Implement searching (retrieving results in json)
-rwxr-xr-xblq14
1 files changed, 14 insertions, 0 deletions
diff --git a/blq b/blq
new file mode 100755
index 0000000..0941da8
--- /dev/null
+++ b/blq
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+# Perform a search on Blocket.se (API v6, Nov 2020)
+
+test -z "$1" && { echo usage: $0 query 1>&2; exit 1; }
+
+# Format query string
+q=`printf '%s\n' "$1" | sed 's/ /%20/g'`
+
+# Retrieve authorization token
+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"