From 81eecc6614f277fe3f1fd69c98c5acf9e212f822 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Sun, 12 Dec 2021 14:39:35 +1000 Subject: [PATCH] wallabag refresh completed --- wallabag-refresh/.envrc | 0 wallabag-refresh/main.py | 45 ++++++++++++++++++++++++++++++++++++++ wallabag-refresh/shell.nix | 28 ++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 wallabag-refresh/.envrc create mode 100644 wallabag-refresh/main.py create mode 100644 wallabag-refresh/shell.nix diff --git a/wallabag-refresh/.envrc b/wallabag-refresh/.envrc new file mode 100644 index 0000000..e69de29 diff --git a/wallabag-refresh/main.py b/wallabag-refresh/main.py new file mode 100644 index 0000000..678f3f7 --- /dev/null +++ b/wallabag-refresh/main.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +import json +import requests +from icecream import ic +import time + +# settings +my_host = 'http://read.mossnet.lan' +oauth_url = '/oauth/v2/token' +params = {'username': 'anish', + 'password': 'wallabag', + 'grant_type': 'password', + 'client_id': '2_4mo0x9udt4owwwo0kg8g004okgos0ccsgggg8c0o0484kc484s', + 'client_secret': '1nv0k19p3mck4sk4kc0wcc8ssc44o80okcggccwk8cckkgww00', + 'extension': 'json'} + +def main(): + # get a new token + header = {} + try: + request = requests.get(my_host+oauth_url, params=params) + content = json.loads(request.content) + access_token = content['access_token'] + expires = time.time() + content['expires_in'] + header = {'Authorization': "Bearer {0}".format(access_token)} + # dns error + except (requests.exceptions.ConnectionError, requests.exceptions.MissingSchema): + ic("Could not connect") + exit + + # get all entries + count = 0 + entries = requests.get(my_host+'/api/entries', params=params, headers=header) + entries = json.loads(entries.content) + for entry in entries['_embedded']['items']: + if entry['content'] == 'wallabag can\'t retrieve contents for this article. Please troubleshoot this issue.\n': + r = requests.patch(my_host+'/api/entries/{0}/reload'.format(entry['id']), params=params, headers=header) + count = count + 1 + print("Reloading {0}, title: {1}".format(entry['id'], entry['title'])) + + print("{} entries reloaded".format(count)) + return 0 + +if __name__ == '__main__': + main() diff --git a/wallabag-refresh/shell.nix b/wallabag-refresh/shell.nix new file mode 100644 index 0000000..3d84c08 --- /dev/null +++ b/wallabag-refresh/shell.nix @@ -0,0 +1,28 @@ +# shell.nix +{ pkgs ? import {} }: +let + wallabagapi = pkgs.python38Packages.buildPythonPackage rec { + pname = "wallabag-client"; + version = "1.8.2"; + + src = pkgs.python38Packages.fetchPypi { + inherit pname version; + sha256 = "sha256-jqd0mehCHX/SVb2YHdDpCwKFrV5FjgLavdaMEo2jmfA="; + }; + propagatedBuildInputs = with pkgs.python38Packages; [ httpx setuptools_scm ]; + doCheck = false; + }; + customPython = pkgs.python38.buildEnv.override { + extraLibs = [ pkgs.python38Packages.requests pkgs.python38Packages.icecream ]; + }; +in +pkgs.mkShell { + buildInputs = [ + customPython + # other dependencies + ]; + shellHook = '' + # maybe set more env-vars + ''; +} +