I have a program that try to download hackernews locally.
What it does is simple, it fetch the max identifier and
http-get each json value starting with the most recent
item. I use n-for-each-par-map with 16 threads I have
8 cores.
Here is the full program:
(define-module (hn))
(use-modules (srfi srfi-1))
(use-modules (ice-9 receive))
(use-modules (ice-9 threads))
(use-modules (ice-9 iconv))
(use-modules (web client))
(use-modules (json))
(define (max-id)
(receive (response body) (http-get
"https://hacker-news.firebaseio.com/v0/maxitem.json")
(string->number (bytevector->string body "utf-8"))))
(define (download uid)
(catch #t
(lambda ()
(let* ((uid (1+ uid))
(url "https://hacker-news.firebaseio.com/v0/item/~a.json")
(url (format #f url uid)))
(cons uid
(json-string->scm
(call-with-values (lambda () (http-get url))
(lambda (response body)
(bytevector->string body "utf-8")))))))
(lambda _ '())))
(define (store pair)
(if (null? pair)
(format #t "X\n")
(let ((port (open-file "hn.scm" "a")))
(format #t "~a\n" (car pair))
(write (cdr pair) port)
(close port))))
(define (dump)
(n-for-each-par-map 16 store download (reverse (iota (max-id)))))
(dump)
It also requires json module from
https://raw.githubusercontent.com/a-guile-mind/Culturia/master/src/json.scm
How can I debug this?
--
Amirouche ~ amz3 ~ http://www.hyperdev.fr