From: Siraaj Khandkar Date: Tue, 10 Nov 2020 14:02:03 +0000 (-0500) Subject: Refactor timeline builder X-Git-Tag: 0.1.0~9 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=9a6a9f9a4781816980dd41221b8f238641134ce5;p=tt.git Refactor timeline builder --- diff --git a/tt b/tt index 8e1cb12..8b66a2e 100755 --- a/tt +++ b/tt @@ -83,35 +83,31 @@ [i (in-naturals)]) (msg-print (odd? i) msg))) +(define (feed->msgs feed) + (log-info "downloading feed nick:~a uri:~a" + (feed-nick feed) + (feed-uri feed)) + (with-handlers + ([exn:fail:network? + (λ (e) + (log-error "network error nick:~a uri:~a exn:~a" + (feed-nick feed) + (feed-uri feed) + e) + #f)] + [integer? + (λ (status) + (log-error "http error nick:~a uri:~a status:~a" + (feed-nick feed) + (feed-uri feed) + status) + #f)]) + (str->msgs [feed-nick feed] [uri-fetch (feed-uri feed)]))) + +; TODO timeline contract : time-sorted list of messages (define (timeline feeds) - (let* ([timelines - (filter-map - (λ (feed) - (log-info "processing feed nick:~a uri:~a" - (feed-nick feed) - (feed-uri feed)) - (with-handlers - ([exn:fail:network? - (λ (e) - (log-error "network error nick:~a uri:~a exn:~a" - (feed-nick feed) - (feed-uri feed) - e) - #f)] - [integer? - (λ (status) - (log-error "http error nick:~a uri:~a status:~a" - (feed-nick feed) - (feed-uri feed) - status) - #f)]) - (str->msgs [feed-nick feed] [uri-fetch (feed-uri feed)]))) - feeds)] - [timeline - (append* timelines)] - [timeline - (sort timeline (λ (a b) [< (msg-tm_epoch a) (msg-tm_epoch b)]))]) - timeline)) + (sort (append* (filter-map feed->msgs feeds)) + (λ (a b) [< (msg-tm_epoch a) (msg-tm_epoch b)]))) (define (we-are-twtxt) (let* ([uri