scripts

custom scripts and utils
git clone git://git.pyratebeard.net/scripts.git
Log | Files | Refs | README

commit eadec52c1a2ce28ae6518d8eeaf454c32c33e2af
parent fe8275f455d2fd0648b5aa075cce191c5e4b5fcb
Author: pyratebeard <root@pyratebeard.net>
Date:   Tue, 30 Jan 2024 11:33:14 +0000

random readlist

Diffstat:
Abin/.local/bin/rrl | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+), 0 deletions(-)

diff --git a/bin/.local/bin/rrl b/bin/.local/bin/rrl @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# ██ +# ░██ +# ██████ ██████ ░██ +# ░░██░░█░░██░░█ ░██ +# ░██ ░ ░██ ░ ░██ +# ░██ ░██ ░██ +# ░███ ░███ ███ +# ░░░ ░░░ ░░░ +# random readlist + +import requests +import random +from subprocess import check_output +import argparse + +AUTH_TOKEN = check_output("pass websites/linkding/api_token", shell=True).splitlines()[0].decode("utf-8") +LINKDING_URL = "http://linkding" +LINKDING_PORT = "9090" +ENDPOINT = "/api/bookmarks" +QUERY = "?q=!unread+%23readlist+" + +api_url = LINKDING_URL + ":" + LINKDING_PORT + ENDPOINT + +# mark item as read +# requires 'id' +def mark_read(id): + requests.patch(api_url + '/481/', {'unread': False}, headers={'Authorization': 'Token ' + AUTH_TOKEN}) + +# select one random url +# from unread list +def random_unread(): + response = requests.get(api_url + QUERY, headers={'Authorization': 'Token ' + AUTH_TOKEN}) + json_data = response.json() if response and response.status_code == 200 else None + random_item = random.sample(json_data['results'], 1) + + print("%s %s" % (random_item[0]['id'], random_item[0]['url'])) + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-r", "--read", help = "Mark read", required = False) + args = parser.parse_args() + + # if id provided mark item as read + if args.read: + id = args.read + mark_read(id) + # otherwise print a random url + else: + random_unread() + +main()