From: Siraaj Khandkar Date: Thu, 2 Dec 2021 01:05:36 +0000 (-0500) Subject: Write url-nick-hist to a single file in addition to multiple X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=8532efc94a5bba6b83ba23e0a2e0a52a96e01931;p=tt.git Write url-nick-hist to a single file in addition to multiple --- diff --git a/info.rkt b/info.rkt index 26782f8..562c237 100644 --- 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 ")) (define deps diff --git a/tt.rkt b/tt.rkt index 58419dc..d527bb4 100644 --- a/tt.rkt +++ b/tt.rkt @@ -855,13 +855,33 @@ (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) (stringdir (-> 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 @@ -874,6 +894,13 @@ 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)