Newsbeuter bookmark to Wallabag

Posted on Fri, 25 Nov 2016

Newsbeuter bookmark to Wallabag

Newsbeuter is rss/atom feed reader for text terminals which contains a plugin-based bookmark system. This allows us to call a command each time we bookmark an article. In the present case, we’ll use a simple python script to send the url, title and even tags to our Wallabag instance.

To call the API we’ll use the implementation by @foxmask :

pip install --user wallabag_api

Next, copy the script below in a new file, we’ll call it script.py.

Warning

Remember that it will contain your wallabag credentials, so don’t place it anywhere. For example, restrict the script permission : chmod 700 script.py.

Don’t forget to replace the values in params & my_host accordingly to your wallabag instance.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 #!/usr/bin/env python3

 import sys
 from wallabag_api.wallabag import Wallabag

 # settings
 params = {'username': 'username',
         'password': 'password',
         'client_id': 'client_id',
         'client_secret': 'client_secret'}

 my_host = 'https://host.com'

 # get token
 token = Wallabag.get_token(host=my_host, **params)

 # create a post
 wall = Wallabag(host=my_host, client_secret='mysecret', client_id='myid',
                 token=token)

 my_url = sys.argv[1]
 my_title = sys.argv[2]
 #  We are using newsbeuter description entry to provide wallabag tags.
 #  Tags must be separated by a comma.
 try:
     my_tags = sys.argv[3].split(',')
     wall.post_entries(url=my_url, title=my_title, tags=my_tags)
 except IndexError:
     wall.post_entries(url=my_url, title=my_title)

We need to configure newsbeuter to call this script each time we bookmark an item. To do so, just add this line to your newsbeuter configuration file in ~/.newsbeuter/config :

bookmark-cmd "/path-of-the-script/script.py"

And it’s ready ! Don’t forget that we’re using the description entry to provide wallabag tags separated by commas.

© octogene. Built using Pelican. Theme adapted from pelican-svbhack available on github.