diff options
author | Christopher R. Nelson <christopher.nelson@languidnights.com> | 2023-06-19 13:03:52 -0400 |
---|---|---|
committer | Christopher R. Nelson <christopher.nelson@languidnights.com> | 2023-06-19 13:03:52 -0400 |
commit | 33f3751e8228086c577e6d38c9b6bcbce9febfea (patch) | |
tree | dd3a3b70ca8e0bedffd9bad73cefd37e81585931 /scripts/rh-client.scm.in | |
parent | cf8ac29ff959d8c5ac8edf23cbfca1be16328f63 (diff) |
feat: add next, new, and consume functions
Diffstat (limited to 'scripts/rh-client.scm.in')
-rwxr-xr-x | scripts/rh-client.scm.in | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/scripts/rh-client.scm.in b/scripts/rh-client.scm.in index d81acc4..64dfde6 100755 --- a/scripts/rh-client.scm.in +++ b/scripts/rh-client.scm.in @@ -1,12 +1,11 @@ #!/usr/bin/env guile !# -(define-module (reading-heap client)) - (use-modules (simple-zmq) (config) (config api) (config parser sexp) - (config licenses)) + (config licenses) + (json)) (define config (configuration @@ -27,12 +26,43 @@ (test boolean?) (character #f)) (switch + (name 'title) + (synopsis "title of the new media") + (default "Foundation Trilogy") + (test string?) + (character #t)) + (switch + (name 'author) + (synopsis "author of the new media") + (default "Isaac Asimov") + (test string?) + (character #t)) + (switch + (name 'location) + (synopsis "location of the new media") + (default "https://openlibrary.org/books/OL20930675M/The_foundation_trilogy") + (test string?) + (character #t)) + (switch + (name 'priority) + (synopsis "priority of the new media") + (default "1") + (test string?) + (character #t)))) + (subcommands + (list + (configuration (name 'next) (synopsis "get the next media to consume") - (default #f) - (test boolean?) - (character #t)) - )) + (wanted '((keywords . (service-socket))))) + (configuration + (name 'new) + (synopsis "add new media to the heap") + (wanted '((keywords . (service-socket title author location priority))))) + (configuration + (name 'consume) + (synopsis "remove the next media from the heap") + (wanted '((keywords . (service-socket))))))) (directory (list (in-home ".reading-heap/") (path (given (string-append (or (getenv "XDG_CONFIG_HOME") @@ -51,15 +81,43 @@ (define (rh-client-next) (zmq-send client-socket "next") - (let ((msg (zmq-receive-bytevector client-socket 65335))) + (let ((msg (zmq-receive-bytevector client-socket 1500))) (display (bv->string msg)))) +(define (rh-client-new json) + (zmq-send client-socket "new") + (zmq-receive client-socket 1500) + (zmq-send client-socket json) + (display (zmq-receive client-socket 1500)) + (zmq-send client-socket "next") + (display (zmq-receive client-socket 1500))) + +(define (rh-client-consumed) + (zmq-send client-socket "consume") + (display (zmq-receive client-socket 1500))) + +(define (json-from-args priority title author location) + (scm->json-string `(("priority" . ,priority) + ("title" . ,title) + ("author" . ,author) + ("location" . ,location)))) + (define (main cmd-line) (let ((options (getopt-config-auto cmd-line config))) (when (option-ref options 'write) (options-write options)) - (when (option-ref options 'next) - (client-setup (option-ref options 'service-socket)) - (rh-client-next)))) + (cond ((string=? (cadr (full-command options)) "next") + (client-setup (option-ref options 'service-socket)) + (rh-client-next)) + ((string=? (cadr (full-command options)) "new") + (client-setup (option-ref options 'service-socket)) + (rh-client-new (json-from-args (string->number (option-ref options 'priority)) + (option-ref options 'title) + (option-ref options 'author) + (option-ref options 'location)))) + ((string=? (cadr (full-command options)) "consume") + (client-setup (option-ref options 'service-socket)) + (rh-client-consumed)) + (#t (emit-help options))))) (main (command-line)) |