(struct msg (tm_epoch tm_rfc3339 nick text))
(struct feed (nick uri))
-(define (msg<-toks nick toks)
- (define tm_rfc3339 (list-ref toks 0))
- (define tok_text (list-ref toks 1))
- (define t (string->rfc3339-record tm_rfc3339))
- ; TODO handle tz offset
- (define tm_epoch (find-seconds [rfc3339-record:second t]
- [rfc3339-record:minute t]
- [rfc3339-record:hour t]
- [rfc3339-record:mday t]
- [rfc3339-record:month t]
- [rfc3339-record:year t]))
- (msg tm_epoch tm_rfc3339 nick tok_text))
+(define (str->lines str)
+ (string-split str (regexp "[\r\n]+")))
+
+(define (str->msg nick str)
+ (if (not (regexp-match? re-msg-begin str))
+ (begin
+ (log-debug "Non-msg line from nick:~a, line:~a" nick str)
+ #f)
+ (let ([toks (string-split str (regexp "\t+"))])
+ (if (not (= 2 (length toks)))
+ (begin
+ (log-warning "Invalid msg line from nick:~a, msg:~a" nick str)
+ #f)
+ (let*
+ ([tm_rfc3339 (list-ref toks 0)]
+ [tok_text (list-ref toks 1)]
+ [t (string->rfc3339-record tm_rfc3339)]
+ ; TODO handle tz offset
+ [tm_epoch (find-seconds [rfc3339-record:second t]
+ [rfc3339-record:minute t]
+ [rfc3339-record:hour t]
+ [rfc3339-record:mday t]
+ [rfc3339-record:month t]
+ [rfc3339-record:year t])])
+ (msg tm_epoch tm_rfc3339 nick tok_text))))))
+
+(define (str->msgs nick str)
+ (filter-map (λ (line) (str->msg nick line)) (str->lines str)))
(define (uri-fetch uri)
(log-info "GET ~a" uri)
[i (in-naturals)])
(msg-print (odd? i) msg)))
-(define (str->lines str)
- (string-split str (regexp "[\r\n]+")))
-
-(define (str->msgs nick str)
- (let* ([lines
- (str->lines str)]
- [msg_lines
- (filter (λ (l) (regexp-match? re-msg-begin l)) lines)]
- [msgs
- (begin
- (log-debug "nick:~a lines:~a msg_lines:~a"
- nick
- (length lines)
- (length msg_lines))
- (filter-map
- (λ (line)
- (define toks (string-split line (regexp "\t+")))
- (if (= 2 (length toks))
- (msg<-toks nick toks)
- (begin
- (log-warning "Invalid msg from nick:~a, msg:~a" nick line)
- #f))
- )
- msg_lines))])
- msgs))
-
(define (timeline feeds)
(let* ([timelines
(filter-map