Using Wallabag as Newsboat Bookmarking Backend

2023-11-27

This article describes how you can use the read it later service wallabag with newsboat rss feed reader.

Motivation

I'm using newsboat since some time and want to combine it with my self-hosted wallabag read-it later instance. Based on the idea from 0x61 and its honk-cli, I decided to give curl and a little shell script a try to clue both worlds together.

Newsboat

Newsboat supports setting of bookmarks by defining a dedicated application for handling. By setting:

bookmark-cmd ".newsboat/bookmark.sh"

The bookmark-cmd will provide an url as the first and only parameter to the given process. In that case, bookmark.sh.

The actual shell script

https://doc.wallabag.org/en/developer/api/oauth#obtaining-a-access-token

Because my wallabag instance requires a token-based authentication we need to get a token from the instance first. Consectuive API calls towards the REST-API are prefixed with that token.

For getting a token let's reate a $HOME/wallabag.cfg with the content. Within that file we define the required fields for getting an access token.

data-ascii = "grant_type=password&client_id=<client_id>&client_secret=<secret>&username=<username>&password=<pass>"

That information will be used by curl for getting the initial access_token like shown in the following script.

#!/bin/sh

[ $# -eq 0 ] && { echo "Usage: $0 url"; exit 1; }
[ ! -f "$HOME/wallabag.cfg" ] && { echo "$HOME/wallabag.cfg not found"; exit 1; } 

response=$(curl --config $HOME/wallabag.cfg -s \
               "https://www.wallabag.it/oauth/v2/token")
token=$(echo "${response}" | awk 'BEGIN{RS=","; FS=":"} /access_token/{print $2}')

# remove leading/trailing quotes
token="${token%\"}"
token="${token#\"}"

# set entries
curl -s -X POST -d "access_token=${token}&url=$1" \
       "https://www.wallabag.it/api/entries.json" >/dev/null

You can test the script as such by calling it via command line like:

./bookmark.sh https://example.org

References

https://x61.sh/log/2022/12/20221205T205745-honk-cli.html