hi, it's mike ʕ•ᴥ•ʔノ

A Wallabag bookmarking script for Newsboat

I don’t have any idea what was going wrong where, but I found a “post to Wallabag” (previously) sh script that worked great from the command line, but wouldn’t run within Newsboat. So I took the script apart, converted it to Ruby/httparty, and it runs fine in this form.

Now I have two scripts for bookmarking in Newsboat, but it only has one reserved key for bookmarking a post. It does have macros, though, so you can use one to set the bookmarking command to a given script and bind it to something memorable. My mutt convention is to lead macros with a period, so I kept that here by unbinding Newsboat’s default macro prefix (,) and setting “.”.

So, .l to save to Linkding, .w to save to Wallabag:

1# macros
2bind-key . macro-prefix
3unbind-key ,
4macro w set bookmark-cmd "op run --env-file=\"$HOME/.env\" -- ~/bin/wallabag.rb"; bookmark
5macro l set bookmark-cmd "op run --env-file=\"$HOME/.env\" -- ~/bin/linkding.rb"; bookmark

And here’s the Wallabag bookmarking script:

 1#!/usr/bin/env ruby
 2
 3require 'httparty'
 4require 'json'
 5
 6entry_url = ARGV[0]
 7
 8wallabag_url="https://reader.example.net"
 9
10client_id = ENV['WALLABAG_CLIENT']
11client_secret = ENV['WALLABAG_SECRET']
12username = ENV['WALLABAG_USER']
13password = ENV['WALLABAG_PASSWORD']
14
15token_params = {grant_type: "password", client_id: client_id, client_secret: client_secret, username: username, password: password}
16token_req = HTTParty.post("#{wallabag_url}/oauth/v2/token", body: token_params)
17access_token = token_req["access_token"]
18
19headers = {'Content-Type' => "application/json", 'Authorization' => "Bearer #{access_token}"}
20params = {url: entry_url, starred: 0, archive: 0}
21resp = HTTParty.post("#{wallabag_url}/api/entries.json", body: params.to_json, headers: headers)

#Newsboat #Wallabag #Ruby #Rss