Write url-nick-hist to a single file in addition to multiple
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 2 Dec 2021 01:05:36 +0000 (20:05 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 2 Dec 2021 01:05:36 +0000 (20:05 -0500)
info.rkt
tt.rkt

index 26782f8..562c237 100644 (file)
--- a/info.rkt
+++ b/info.rkt
@@ -6,7 +6,7 @@
 (define pkg-desc
   "twtxt client")
 (define version
-  "0.30.1")
+  "0.31.0")
 (define pkg-authors
   '("Siraaj Khandkar <siraaj@khandkar.net>"))
 (define deps
diff --git a/tt.rkt b/tt.rkt
index 58419dc..d527bb4 100644 (file)
--- a/tt.rkt
+++ b/tt.rkt
     (hash)
     msgs))
 
-(: update-nicks-history-files (-> Nick-Hist Void))
-(define (update-nicks-history-files nick-hist)
+(: url-nick-hist->file (-> Nick-Hist Path-String Void))
+(define (url-nick-hist->file url-nick-hist filepath)
+  (define out (open-output-file filepath #:exists 'replace))
+  (for-each
+    (match-lambda
+      [(cons url nick->hist)
+       (displayln (url->string url) out)
+       (for-each (match-lambda
+                   [(cons nick (Hist freq last))
+                    (displayln (format "    ~a ~a ~a" nick freq last) out)])
+                 (sort (hash->list nick->hist)
+                       (match-lambda**
+                         [((cons _ (Hist a _)) (cons _ (Hist b _)))
+                          (> a b)])))])
+    (sort
+      (hash->list url-nick-hist)
+      (λ (a b) (string<? (url-host (car a))
+                         (url-host (car b))))))
+  (close-output-port out))
+
+(: url-nick-hist->dir (-> Nick-Hist Path-String Void))
+(define (url-nick-hist->dir url-nick-hist dirpath)
   (hash-for-each
-    nick-hist
+    url-nick-hist
     (λ (url nick->hist)
        (define filename (string-append (uri-encode (url->string url)) ".txt"))
-       (define filepath (build-path tt-home-dir "nicks" "seen" filename))
+       (define filepath (build-path dirpath filename))
        (make-parent-directory* filepath)
        (display-lines-to-file
          (map (match-lambda
          filepath
          #:exists 'replace))))
 
+; TODO rename: Nick-Hist --> Url-Nick-Hist
+(: update-nicks-history-files (-> Nick-Hist Void))
+(define (update-nicks-history-files url-nick-hist)
+  (define nicks-dir (build-path tt-home-dir "nicks"))
+  (url-nick-hist->file url-nick-hist (build-path nicks-dir "seen.txt"))
+  (url-nick-hist->dir  url-nick-hist (build-path nicks-dir "seen")))
+
 (: nick-hist-most-by (-> Nick-Hist Url (-> Hist Nonnegative-Integer) (Option String)))
 (define (nick-hist-most-by url->nick->hist url by)
   (match (hash-ref url->nick->hist url #f)
This page took 0.027881 seconds and 4 git commands to generate.