Skip to content

Instantly share code, notes, and snippets.

@benediktg
Last active January 21, 2023 18:35
Show Gist options
  • Save benediktg/9a29b923235d6c7c2fe6833b240a08ee to your computer and use it in GitHub Desktop.
Save benediktg/9a29b923235d6c7c2fe6833b240a08ee to your computer and use it in GitHub Desktop.
Add new articles using the new wallabag API and Python
#!/usr/bin/env python3
import requests
# only these 5 variables have to be set
HOST = 'https://wallabag.example.org'
USERNAME = 'username'
PASSWORD = 'password'
CLIENTID = 'cryptic_client_id'
SECRET = 'secret'
gettoken = {'username': USERNAME, 'password': PASSWORD, 'client_id': CLIENTID, 'client_secret': SECRET, 'grant_type': 'password'}
r = requests.get('{}/oauth/v2/token'.format(HOST), gettoken)
access = r.json().get('access_token')
# can be replaced by a loop over many URLs
url = 'https://example.com' # URL of the article
a = 0 # should the article be already read? 0 or 1
f = 0 # should the article be added as favorited? 0 or 1
article = {'url': url, 'archive': a , 'starred': f, 'access_token': access}
r = requests.post('{}/api/entries.json'.format(HOST), article)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment