From a5d7d58a25c894296423dbae3b29317e91196c38 Mon Sep 17 00:00:00 2001 From: Felisp Date: Thu, 15 Aug 2024 20:46:17 +0200 Subject: [PATCH 1/4] SYNC commit --- project.clj | 2 +- src/rss_thread_watch/feed_generator.clj | 10 +++++----- src/rss_thread_watch/watcher.clj | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/project.clj b/project.clj index 2abe787..382df6f 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject rss-thread-watch "0.4.1-SNAPSHOT" +(defproject rss-thread-watch "0.4.2-SNAPSHOT" :description "RSS based thread watcher" :url "http://example.com/FIXME" :license {:name "AGPL-3.0-only" diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index 33760e5..6047730 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -84,9 +84,8 @@ (map guid-fn actuall-matches))) (defn thread-to-rss-item - "If I wasnt retarded I could have made the cached version look like - rss item already but what can you do. I'll refactor I promise, I just need this done ASAP" ;Todo: do what the docstring says - [t] ;TODO: oh Luna the hardcodes ;;RESUME + "Converts cached thread item to feed item which can be serialized into RSS" + [t host board] ;;NOW2 ;TODO: oh Luna the hardcodes ;;RESUME (let [link-url (str "https://boards.4chan.org/mlp/thread/" (:no t))] ; jesus, well I said only /mlp/ is supported now so fuck it {:title (format "%.2f%% - %s" (:chod t) (:title t)) ;TODO: Generate link from the target somehow, or just include it from API response ;; :url link-url <- this is supposed to be for images according to: https://cyber.harvard.edu/rss/rss.html @@ -96,7 +95,7 @@ (defn generate-feed "Generates feed from matching items" - [query-vec chod-treshold repeat? cache] + [query-vec chod-treshold repeat? cache board-config] (let [items (filter-chod-posts query-vec chod-treshold repeat? cache) head {:title "RSS Thread watcher v0.4.1" ;TODO: hardcoded string here, remake to reference to config.clj :link "https://tools.treebrary.org/thread-watcher/feed.xml" @@ -130,6 +129,7 @@ 60 (Integer/parseInt chod)) (catch Exception e 94))) + board-config (get ) cache @watcher/chod-threads-cache] (println "\n\nRCVD: " rqst) ;; (println rqst) @@ -166,7 +166,7 @@ ;; There shouldn't be any problems with this mime type but if there are ;; replace with "text/xml", or even better, get RSS reader that is not utter shit :header {"Content-Type" "application/rss+xml"} - :body (generate-feed queries real-chod repeat? (watcher/get-thread-data board @watcher/GLOBAL-CONFIG))}) + :body (generate-feed queries real-chod repeat? (watcher/get-thread-data board @watcher/GLOBAL-CONFIG))}) ;NOW3 give board specific config here (catch Exception e ;; Ex-info has been crafted to match HTTP response body so we can send it (if-let [caught (ex-data e)] diff --git a/src/rss_thread_watch/watcher.clj b/src/rss_thread_watch/watcher.clj index 93b068c..ac1ddf1 100644 --- a/src/rss_thread_watch/watcher.clj +++ b/src/rss_thread_watch/watcher.clj @@ -47,6 +47,9 @@ (recur (rest remaining-threads) threads-total (inc index) + ;; NOW: Cache fomrat here + ;; We have to somehow include URL which is a problem since the catalog does not contain any + ;; I of course know how to craft it but the result will be kind of 4chan specific (conj! ret {:title (or (:sub thread) ;We use thread title if thread has it (:com thread) ;we use body if thread has it "") ;Thread has neither, this prevents null pointer From 9c7bae3712ea4d222d49bf7ee9e7984670feb037 Mon Sep 17 00:00:00 2001 From: Felisp Date: Sun, 18 Aug 2024 15:03:30 +0200 Subject: [PATCH 2/4] Include board name in it's config Needs testing --- src/rss_thread_watch/core.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rss_thread_watch/core.clj b/src/rss_thread_watch/core.clj index 7b7058f..4e3c3fd 100644 --- a/src/rss_thread_watch/core.clj +++ b/src/rss_thread_watch/core.clj @@ -83,7 +83,7 @@ '(:boards-enabled) (fn [mp] (u/fmap (fn [k v] - (u/map-apply-defaults v defaults)) + (assoc :name (u/map-apply-defaults v defaults))) mp))) :boards-defaults))) From 8224eab460218e0730327babd24f01cc60024f86 Mon Sep 17 00:00:00 2001 From: Felisp Date: Tue, 20 Aug 2024 22:43:57 +0200 Subject: [PATCH 3/4] Fix wrong URL for dying threads and refactor cache format --- src/rss_thread_watch/core.clj | 2 +- src/rss_thread_watch/feed_generator.clj | 13 ++++++++----- src/rss_thread_watch/watcher.clj | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/rss_thread_watch/core.clj b/src/rss_thread_watch/core.clj index 4e3c3fd..662d6cb 100644 --- a/src/rss_thread_watch/core.clj +++ b/src/rss_thread_watch/core.clj @@ -83,7 +83,7 @@ '(:boards-enabled) (fn [mp] (u/fmap (fn [k v] - (assoc :name (u/map-apply-defaults v defaults))) + (assoc (u/map-apply-defaults v defaults) :name k)) mp))) :boards-defaults))) diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index 6047730..e6b41e6 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -85,8 +85,8 @@ (defn thread-to-rss-item "Converts cached thread item to feed item which can be serialized into RSS" - [t host board] ;;NOW2 ;TODO: oh Luna the hardcodes ;;RESUME - (let [link-url (str "https://boards.4chan.org/mlp/thread/" (:no t))] ; jesus, well I said only /mlp/ is supported now so fuck it + [t host board] + (let [link-url (str host board (:no t))] {:title (format "%.2f%% - %s" (:chod t) (:title t)) ;TODO: Generate link from the target somehow, or just include it from API response ;; :url link-url <- this is supposed to be for images according to: https://cyber.harvard.edu/rss/rss.html :description (format "The thread: '%s' has %.2f%% chance of dying" (:title t) (:chod t)) @@ -101,7 +101,10 @@ :link "https://tools.treebrary.org/thread-watcher/feed.xml" :feed-url "https://tools.treebrary.org/thread-watcher/feed.xml" :description "RSS based thread watcher"} - body (map thread-to-rss-item items)] + body (map #(thread-to-rss-item + %1 + (get board-config :target) + (get board-config :name)) items)] (rss/channel-xml head body))) (defn http-handler @@ -129,7 +132,7 @@ 60 (Integer/parseInt chod)) (catch Exception e 94))) - board-config (get ) + board-config (get-in @watcher/GLOBAL-CONFIG [:boards-enabled board]) cache @watcher/chod-threads-cache] (println "\n\nRCVD: " rqst) ;; (println rqst) @@ -166,7 +169,7 @@ ;; There shouldn't be any problems with this mime type but if there are ;; replace with "text/xml", or even better, get RSS reader that is not utter shit :header {"Content-Type" "application/rss+xml"} - :body (generate-feed queries real-chod repeat? (watcher/get-thread-data board @watcher/GLOBAL-CONFIG))}) ;NOW3 give board specific config here + :body (generate-feed queries real-chod repeat? (watcher/get-thread-data board @watcher/GLOBAL-CONFIG) board-config)}) (catch Exception e ;; Ex-info has been crafted to match HTTP response body so we can send it (if-let [caught (ex-data e)] diff --git a/src/rss_thread_watch/watcher.clj b/src/rss_thread_watch/watcher.clj index ac1ddf1..3588168 100644 --- a/src/rss_thread_watch/watcher.clj +++ b/src/rss_thread_watch/watcher.clj @@ -47,7 +47,6 @@ (recur (rest remaining-threads) threads-total (inc index) - ;; NOW: Cache fomrat here ;; We have to somehow include URL which is a problem since the catalog does not contain any ;; I of course know how to craft it but the result will be kind of 4chan specific (conj! ret {:title (or (:sub thread) ;We use thread title if thread has it From 376245c650d2719d35558c2c51d68fe557ea7247 Mon Sep 17 00:00:00 2001 From: Felisp Date: Tue, 20 Aug 2024 22:46:20 +0200 Subject: [PATCH 4/4] The versions really need to be unified in one place --- src/rss_thread_watch/core.clj | 2 +- src/rss_thread_watch/feed_generator.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rss_thread_watch/core.clj b/src/rss_thread_watch/core.clj index 662d6cb..0969835 100644 --- a/src/rss_thread_watch/core.clj +++ b/src/rss_thread_watch/core.clj @@ -23,7 +23,7 @@ [rss-thread-watch.utils :as u]) (:gen-class)) -(def VERSION "0.4.1") +(def VERSION "0.4.2") ;; Internal default config (def CONFIG-DEFAULT diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index e6b41e6..83a92a8 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -97,7 +97,7 @@ "Generates feed from matching items" [query-vec chod-treshold repeat? cache board-config] (let [items (filter-chod-posts query-vec chod-treshold repeat? cache) - head {:title "RSS Thread watcher v0.4.1" ;TODO: hardcoded string here, remake to reference to config.clj + head {:title "RSS Thread watcher v0.4.2" ;TODO: hardcoded string here, remake to reference to config.clj :link "https://tools.treebrary.org/thread-watcher/feed.xml" :feed-url "https://tools.treebrary.org/thread-watcher/feed.xml" :description "RSS based thread watcher"}