Use lang typed/racket/no-check
[tt.git] / tt.rkt
diff --git a/tt.rkt b/tt.rkt
index 42153ec..2cc2131 100644 (file)
--- a/tt.rkt
+++ b/tt.rkt
@@ -1,32 +1,27 @@
-#lang racket
+#lang typed/racket/no-check
 
 (require openssl/sha1)
 (require racket/date)
-(require (prefix-in info: setup/getinfo))
 (require
   net/http-client
   net/url-string
   net/url-structs)
 
-(require rfc3339-old)
+(require (prefix-in info: "info.rkt"))
 
 (module+ test
   (require rackunit))
 
 (struct msg
-        (
-         ts_epoch   ; Integer
-         ts_rfc3339 ; String
-         nick       ; String
-         uri        ; net/url-structs:url
-         text       ; String
-         ))
+        ([ts_epoch   : Integer]
+         [ts_rfc3339 : String]
+         [nick       : String]
+         [uri        : net/url-structs:url]
+         [text       : String]))
 
 (struct feed
-        (
-         nick ; String
-         uri  ; net/url-structs:url
-         ))
+        ([nick : String]
+         [uri  : net/url-structs:url]))
 
 (define (concurrent-filter-map num_workers f xs)
   ; TODO preserve order of elements OR communicate that reorder is expected
                                   (date->string (seconds->date [msg-ts_epoch msg]) #t))
                     nick uri color text)])))))
 
-; TODO Implement rfc3339->epoch and remove dependency on rfc3339-old
-
 (define str->msg
-  (let ([re (pregexp "^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}(:[0-9]{2})?)(\\.[0-9]+)?([^\\s\t]*)[\\s\t]+(.*)$")])
+  ; TODO Split parsing into 2 stages: 1) line->list; 2) rfc3339->epoch.
+  (let ([re (pregexp "^(([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(:([0-9]{2}))?)(\\.[0-9]+)?([^\\s\t]*)[\\s\t]+(.*)$")])
     (λ (nick uri str)
        (with-handlers*
          ([exn:fail?
                  str nick (url->string uri) e)
                #f)])
          (match (regexp-match re str)
-           [(list _wholething ts s _fractional tz text)
+           [(list _wholething ts yyyy mm dd HH MM _:SS SS _f tz text)
             (let*
-              ([ts_rfc3339 (string-append ts (if s "" ":00") (if tz tz ""))]
-               [t          (string->rfc3339-record ts_rfc3339)]
-               [s          (rfc3339-record:second t)]
                ; TODO handle tz offset
-               [ts_epoch (find-seconds [if s s 0]
-                                       [rfc3339-record:minute t]
-                                       [rfc3339-record:hour   t]
-                                       [rfc3339-record:mday   t]
-                                       [rfc3339-record:month  t]
-                                       [rfc3339-record:year   t])])
+              ([ts_rfc3339 (string-append ts (if SS "" ":00") (if tz tz ""))]
+               [ts_epoch (find-seconds (if SS (string->number SS) 0)
+                                       (string->number MM)
+                                       (string->number HH)
+                                       (string->number dd)
+                                       (string->number mm)
+                                       (string->number yyyy))])
               (msg ts_epoch ts_rfc3339 nick uri text))]
            [_
              (log-debug "Non-msg line from nick:~a, line:~a" nick str)
 (define user-agent
   (let*
     ([prog-name      "tt"]
-     [prog-version   ((info:get-info (list prog-name)) 'version)]
+     [prog-version   (info:#%info-lookup 'version)]
      [prog-uri       "https://github.com/xandkar/tt"]
      [user-feed-file (expand-user-path "~/twtxt-me.txt")]
      [user
This page took 0.0308079999999999 seconds and 4 git commands to generate.