commit f004b8ce4bf920044b49e7f0d06f59edeb556343
parent 24314f1526dfe7aa9fb3af8ea7f99d18472654b9
Author: lou woell <lou@repetitions.de>
Date:   Mon, 30 Mar 2026 17:55:36 +0200

restructure xml-match, remove redundant dependency

Diffstat:
Mlinkhut.scm | 103+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 54 insertions(+), 49 deletions(-)

diff --git a/linkhut.scm b/linkhut.scm @@ -53,8 +53,7 @@ (web client) (sxml simple) - (sxml match) - (sxml xpath)) + (sxml match)) ;; TODO: make this a bit more user friendly (define token (call-with-input-file "./token" read-line)) @@ -95,57 +94,63 @@ #:query (if query (build-query query) query)) #:headers `((authorization . (basic . ,token)))))) (when (= 200 (response-code resp)) - (sxml->lisp (xml->sxml body #:trim-whitespace? #t))))) + (xml->lisp body)))) (define (timestamp string) (string->date string "~Y~m~d~H~M~S~z")) -(define (sxml->lisp x) - (sxml-match x - ((*TOP* ,pi ,(data)) data) - - ((posts (@ (user ,user)) ,(post) ...) - `(,post ...)) - - ((tags ,(tag) ...) tag) - - ((tag (@ (tag ,name) (count ,n))) - (list name (string->number n))) - - ((post (@ (tag ,tags) - (description ,desc) - (extended ,ext) - (hash ,hash) - (href ,link) - (others ,others) - (time ,time) - (meta ,meta))) - (list (cons 'id (string->number hash 16)) - (cons 'title desc) - (cons 'note ext) - (cons 'link link) - (cons 'time (timestamp time)) - (cons 'count (string->number others)) - (cons 'meta (string->number meta 16)) - (cons 'tags (string-split tags char-whitespace?)))) - - ((result (@ (code ,c))) - (string= "done" c)) - - ((dates (@ (tag ,tag) - (user ,user)) - ,(date) ...) - (list (cons 'tag tag) date)) - - ((date (@ (count ,count) - (date ,date))) - (list date (string->number count))) - - ((update (@ (time ,t) - (code ,c) - (inboxnew ,i))) - - (list 'update (timestamp t) (string= "done" c) i)))) +(define (xml->lisp xml) + (sxml-match + (xml->sxml xml #:trim-whitespace? #t) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; + ;; decode linkhut responses: + + ((*TOP* ,pi ,(data)) data) + + ((posts (@ (user ,user)) ,(post) ...) + `(,post ...)) + + ((tags ,(tag) ...) tag) + + ((tag (@ (tag ,name) (count ,n))) + (list name (string->number n))) + + ((post (@ (tag ,tags) + (description ,desc) + (extended ,ext) + (hash ,hash) + (href ,link) + (others ,others) + (time ,time) + (meta ,meta))) + (list (cons 'id (string->number hash 16)) + (cons 'title desc) + (cons 'note ext) + (cons 'link link) + (cons 'time (timestamp time)) + (cons 'count (string->number others)) + (cons 'meta (string->number meta 16)) + (cons 'tags (string-split tags char-whitespace?)))) + + ((result (@ (code ,c))) + (string= "done" c)) + + ((dates (@ (tag ,tag) + (user ,user)) + ,(date) ...) + (list (cons 'tag tag) date)) + + ((date (@ (count ,count) + (date ,date))) + (list date (string->number count))) + + ((update (@ (time ,t) + (code ,c) + (inboxnew ,i))) + + (list 'update (timestamp t) (string= "done" c) i)))) ;; Gets value of property PROP of POST.