diff --git a/src/dhyan/connections/starred.clj b/src/dhyan/connections/starred.clj index 0729778..2a87561 100644 --- a/src/dhyan/connections/starred.clj +++ b/src/dhyan/connections/starred.clj @@ -1,2 +1,21 @@ (ns dhyan.connections.starred - (:require [babashka.fs])) + (:require + [cheshire.core :as json] + [clojure.java.io :as io])) + +(defn read-json-starred + [] + (with-open [rdr (io/reader "./data/starred.json")] + (reduce conj [] (json/parsed-seq rdr)))) + +(def json (atom "")) + +(defn init + [] + (let [j (read-json-starred)] + (reset! json (first j)))) + +(defn random-stared + [] + (init) + (clojure.walk/keywordize-keys (rand-nth (deref json)))) diff --git a/src/dhyan/main.clj b/src/dhyan/main.clj index be66152..ad51a01 100644 --- a/src/dhyan/main.clj +++ b/src/dhyan/main.clj @@ -2,6 +2,7 @@ (:require [dhyan.connections.shaarli :as shaarli] [dhyan.connections.wallabag :as wallabag] [dhyan.connections.files :as files] + [dhyan.connections.starred :as starred] [clojure.string :as string] [dhyan.connections.matrix :as matrix])) @@ -26,6 +27,10 @@ "\n available at: " (get wallabag-entry-of-the-day :url) "\n tagged as: " (string/join ", " (get wallabag-entry-of-the-day :tags))) on-this-day-file (files/slurp-if-file) - message (string/join "\n\n" [shaarli-message wallabag-message on-this-day-file])] + random-starred (starred/random-stared) + starred-message (str "Random starred article: \n" + (get random-starred :title) + (get random-starred :url)) + message (string/join "\n\n" [shaarli-message wallabag-message on-this-day-file starred-message])] (matrix/post-message message)))