Refactor timeline builder
authorSiraaj Khandkar <siraaj@khandkar.net>
Tue, 10 Nov 2020 14:02:03 +0000 (09:02 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Tue, 10 Nov 2020 14:02:03 +0000 (09:02 -0500)
tt

diff --git a/tt b/tt
index 8e1cb12..8b66a2e 100755 (executable)
--- a/tt
+++ b/tt
         [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
This page took 0.036017 seconds and 4 git commands to generate.