Return Entire thread

SchemeBBS continuation thread

1 Name: Anonymous 2017-03-24 13:24
;; torsocks guile this.scm

(use-modules (web client)
(web response)
(ice-9 receive))

(define (print p) (write p) (newline))

(define schemebbs-endpoint "http://hz27w5o3zlhptx7v.onion/schemebbs")

(define (schemebbs query)
(let ((query-string (with-output-to-string (lambda () (write query)))))
(receive (response body)
(http-post schemebbs-endpoint #:body query-string)
(unless (= 200 (response-code response))
(error "bad http response code" (response-code response)))
(with-input-from-string body read))))

(let ((v (schemebbs '(version))))
(unless (>= v 2)
(error "I only work with version 2 or higher" v)))

(print (schemebbs '(version)))
(print (schemebbs '(get 0)))
;;(print (schemebbs '(posts> 0)))

(define db-max 0)
(define db #f)

(when (access? "db.scm" F_OK)
(with-input-from-file "db.scm"
(lambda ()
(set! db-max (read))
(set! db '())
(let loop ((thing (read)))
(if (eof-object? thing)
(begin (set! db (cons thing db))
(loop (read))))))))

(print `(reading in the new posts since ,db-max))

(define newest-posts (schemebbs `(posts>= ,(+ 1 db-max))))

(print newest-posts)

(for-each (lambda (new)
(let ((new-id (cdr (assoc 'id new))))
(when (> new-id db-max)
(set! db-max new-id))))

(print `(got new posts up to ,db-max saving...))

(with-output-to-file "db.scm"
(lambda ()
(print db-max)
(when db
(for-each print db))
(for-each print newest-posts)))

(print 'done)

Return Entire thread
Leave this field blank: