Compare commits

...

3 commits

4 changed files with 33 additions and 20 deletions

View file

@ -1,4 +1,4 @@
(defproject rss-thread-watch "0.4.3-SNAPSHOT" (defproject rss-thread-watch "0.4.4-SNAPSHOT"
:description "RSS based thread watcher" :description "RSS based thread watcher"
:url "http://example.com/FIXME" :url "http://example.com/FIXME"
:license {:name "AGPL-3.0-only" :license {:name "AGPL-3.0-only"

View file

@ -14,14 +14,12 @@
:starting-page 7 :starting-page 7
;; Default ChOD to use if none is specified by the user ;; Default ChOD to use if none is specified by the user
:default-chod 94 :default-chod 94
;; If you want to do some preprocessing beforehand, you can override ;; This is target for Catalog API requests
;; target URL for the board, but the response must be same the 4chan API would return ;; {board} will be substitued for board
;; /$board/catalog.json will be appended to this link :target "https://api.4chan.org/{board}/catalog.json"
;; This is target for API requests ;; This is where threads actually reside if different from :target
:target "https://api.4chan.org" ;; you can use {board} and {threadnum} for substitutions
;; This host that has the actual threads, /board/thread-no will be appeneded :host "https://boards.4chan.org/{board}/thread/{threadnum}"
;; to this
:host "https://boards.4chan.org"
;; Commented parts bellow are still unimplemented ;; Commented parts bellow are still unimplemented
;; ------ ;; ------
;; Only download catalog when someone requests feed and cache is old ;; Only download catalog when someone requests feed and cache is old

View file

@ -15,6 +15,7 @@
(ns rss-thread-watch.core (ns rss-thread-watch.core
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[clojure.edn :as edn] [clojure.edn :as edn]
[clojure.string :as s]
[clojure.tools.cli :refer [parse-opts]] [clojure.tools.cli :refer [parse-opts]]
[ring.adapter.jetty :as jetty] [ring.adapter.jetty :as jetty]
[ring.middleware.params :as rp] [ring.middleware.params :as rp]
@ -23,7 +24,7 @@
[rss-thread-watch.utils :as u]) [rss-thread-watch.utils :as u])
(:gen-class)) (:gen-class))
(def VERSION "0.4.3") (def VERSION "0.4.4")
;; Internal default config ;; Internal default config
(def CONFIG-DEFAULT (def CONFIG-DEFAULT
@ -35,8 +36,8 @@
:boards-defaults {:refresh-rate 300 :boards-defaults {:refresh-rate 300
:starting-page 7 :starting-page 7
:default-chod 94 :default-chod 94
:target "https://api.4chan.org" :target "https://api.4chan.org/{board}/catalog.json"
:host "https://boards.4chan.org" :host "https://boards.4chan.org/{board}/thread/{threadnum}"
:lazy-load true} :lazy-load true}
:boards-enabled {"/mlp/" {:lazy-load false} :boards-enabled {"/mlp/" {:lazy-load false}
"/g/" {:starting-page 7} "/g/" {:starting-page 7}
@ -76,17 +77,31 @@
(with-open [r (io/reader fl)] (with-open [r (io/reader fl)]
(edn/read (java.io.PushbackReader. r)))))) (edn/read (java.io.PushbackReader. r))))))
(defn config-url-expand
"Expands substitution in :target and :host fields"
[filled-config]
(let [boards (get filled-config :boards-enabled)
selecting '(:target :host)
pattern "{board}"]
(u/fmap (fn [board confs]
(->> (select-keys confs selecting)
(u/fmap (fn [k v]
(s/replace v pattern (s/replace board "/" ""))))
(merge confs)))
boards)))
(defn config-fill-board-defaults (defn config-fill-board-defaults
"Fills every enabled board with default config values" "Fills every enabled board with default config values"
[config] [config]
(let [defaults (:boards-defaults config)] (let [defaults (:boards-defaults config)]
(dissoc (update-in config (-> config
'(:boards-enabled) (update-in '(:boards-enabled)
(fn [mp] (fn [mp]
(u/fmap (fn [k v] (u/fmap (fn [k v]
(assoc (u/map-apply-defaults v defaults) :name k)) (assoc (u/map-apply-defaults v defaults) :name k))
mp))) mp)))
:boards-defaults))) (dissoc :boards-defaults)
(config-url-expand))))
(defn get-some-config (defn get-some-config
"Attempts to get config somehow, "Attempts to get config somehow,

View file

@ -97,7 +97,7 @@
"Generates feed from matching items" "Generates feed from matching items"
[query-vec chod-treshold repeat? cache board-config] [query-vec chod-treshold repeat? cache board-config]
(let [items (filter-chod-posts query-vec chod-treshold repeat? cache) (let [items (filter-chod-posts query-vec chod-treshold repeat? cache)
head {:title "RSS Thread watcher v0.4.3" ;TODO: hardcoded string here, remake to reference to config.clj head {:title "RSS Thread watcher v0.4.4" ;TODO: hardcoded string here, remake to reference to config.clj
:link "https://tools.treebrary.org/thread-watcher/feed.xml" :link "https://tools.treebrary.org/thread-watcher/feed.xml"
:feed-url "https://tools.treebrary.org/thread-watcher/feed.xml" :feed-url "https://tools.treebrary.org/thread-watcher/feed.xml"
:description "RSS based thread watcher"} :description "RSS based thread watcher"}