5 ; TODO caching (use cache by default, unless explicitly asked for update)
7 ; TODO user-defined feed sets (a la twitter lists)
8 ; TODO feed set operations
9 ; TODO timeline as a result of a query (feed set op + filter expressions)
10 ; TODO named timelines
13 ; TODO highlight mentions
14 ; TODO filter on mentions
15 ; TODO highlight hashtags
16 ; TODO filter on hashtags
27 (struct msg (tm_epoch tm_rfc3339 nick text))
28 (struct feed (nick uri))
30 (define (msg-print odd m)
31 (printf "~a \033[1;37m<~a>\033[0m \033[0;~am~a\033[0m~n"
32 (date->string (seconds->date [msg-tm_epoch m]) #t)
38 ; TODO Zulu offset. Maybe in several formats. Which ones?
39 (pregexp "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}"))
41 (define (str->msg nick str)
42 (if (not (regexp-match? re-msg-begin str))
44 (log-debug "Non-msg line from nick:~a, line:~a" nick str)
46 (let ([toks (string-split str (regexp "\t+"))])
47 (if (not (= 2 (length toks)))
49 (log-warning "Invalid msg line from nick:~a, msg:~a" nick str)
52 ([tm_rfc3339 (list-ref toks 0)]
53 [tok_text (list-ref toks 1)]
54 [t (string->rfc3339-record tm_rfc3339)]
55 ; TODO handle tz offset
56 [tm_epoch (find-seconds [rfc3339-record:second t]
57 [rfc3339-record:minute t]
58 [rfc3339-record:hour t]
59 [rfc3339-record:mday t]
60 [rfc3339-record:month t]
61 [rfc3339-record:year t])])
62 (msg tm_epoch tm_rfc3339 nick tok_text))))))
64 (define (str->lines str)
65 (string-split str (regexp "[\r\n]+")))
67 (define (str->msgs nick str)
68 (filter-map (λ (line) (str->msg nick line)) (str->lines str)))
70 (define (uri-fetch uri)
71 (log-info "GET ~a" uri)
72 (define resp (http-get uri))
73 (define status (http-response-code resp))
74 (define body (http-response-body resp))
75 (log-debug "finished GET ~a status:~a body length:~a"
76 uri status (string-length body))
77 ; TODO Handle redirects
78 (if (= status 200) body (raise status)))
80 (define (timeline-print timeline)
83 (msg-print (odd? i) msg)))
85 (define (timeline feeds)
89 (log-info "processing feed nick:~a uri:~a"
95 (log-error "network error nick:~a uri:~a exn:~a"
102 (log-error "http error nick:~a uri:~a status:~a"
107 (str->msgs [feed-nick feed] [uri-fetch (feed-uri feed)])))
112 (sort timeline (λ (a b) [< (msg-tm_epoch a) (msg-tm_epoch b)]))])
115 (define (we-are-twtxt)
117 "https://raw.githubusercontent.com/mdom/we-are-twtxt/master/we-are-twtxt.txt"]
121 (str->lines payload)]
124 (define toks (string-split line))
131 (define (setup-logging)
132 (define logger (make-logger #f #f 'debug #f))
133 (define log-chan (make-log-receiver logger 'debug))
135 [date-display-format 'iso-8601]
137 (define data (sync log-chan))
138 (define level (vector-ref data 0))
139 (define msg (vector-ref data 1))
140 (define ts (date->string (current-date) #t))
141 (eprintf "~a [~a] ~a~n" ts level msg)
143 (current-logger logger))
147 (current-http-response-auto #f)
148 (current-http-user-agent "xandkar/tt 0.0.0")
149 (date-display-format 'rfc2822)
151 (define feeds (we-are-twtxt))
152 (timeline-print (timeline feeds)))