Finish making config URLs more flexible
This commit is contained in:
parent
4c5ad1e923
commit
62f62a967f
4 changed files with 20 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
|||
(defproject rss-thread-watch "0.4.4-SNAPSHOT"
|
||||
(defproject rss-thread-watch "0.4.5-SNAPSHOT"
|
||||
:description "RSS based thread watcher"
|
||||
:url "http://example.com/FIXME"
|
||||
:license {:name "AGPL-3.0-only"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
[rss-thread-watch.utils :as u])
|
||||
(:gen-class))
|
||||
|
||||
(def VERSION "0.4.4")
|
||||
(def VERSION "0.4.5")
|
||||
|
||||
;; Internal default config
|
||||
(def CONFIG-DEFAULT
|
||||
|
@ -83,25 +83,28 @@
|
|||
(let [boards (get filled-config :boards-enabled)
|
||||
selecting '(:target :host)
|
||||
pattern "{board}"]
|
||||
(assoc filled-config
|
||||
:boards-enabled
|
||||
(u/fmap (fn [board confs]
|
||||
(->> (select-keys confs selecting)
|
||||
(u/fmap (fn [k v]
|
||||
(s/replace v pattern (s/replace board "/" ""))))
|
||||
(merge confs)))
|
||||
boards)))
|
||||
boards))))
|
||||
|
||||
(defn config-fill-board-defaults
|
||||
"Fills every enabled board with default config values"
|
||||
[config]
|
||||
(let [defaults (:boards-defaults config)]
|
||||
(-> config
|
||||
(update-in '(:boards-enabled)
|
||||
(as-> config conf
|
||||
(update-in conf
|
||||
'(:boards-enabled)
|
||||
(fn [mp]
|
||||
(u/fmap (fn [k v]
|
||||
(assoc (u/map-apply-defaults v defaults) :name k))
|
||||
mp)))
|
||||
(dissoc :boards-defaults)
|
||||
(config-url-expand))))
|
||||
(dissoc conf :boards-defaults)
|
||||
(config-url-expand conf))))
|
||||
|
||||
(defn get-some-config
|
||||
"Attempts to get config somehow,
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
(defn thread-to-rss-item
|
||||
"Converts cached thread item to feed item which can be serialized into RSS"
|
||||
[t host board]
|
||||
(let [link-url (str host board "thread/" (:no t))] ;Hardcode emergency bugfix
|
||||
(let [link-url (s/replace host "{threadnum}" (str (:no t)))] ;Hardcode emergency bugfix
|
||||
{: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))
|
||||
|
@ -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.4" ;TODO: hardcoded string here, remake to reference to config.clj
|
||||
head {:title "RSS Thread watcher v0.4.5" ;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"}
|
||||
|
@ -128,6 +128,7 @@
|
|||
chod)]
|
||||
(try ;If we can't parse number from chod, use default 94
|
||||
(if (or (vector? chod)
|
||||
;; TODO: Do we seriously parse this twice?
|
||||
(<= (Integer/parseInt chod) 60)) ; Never accept chod lower than 60 TODO: don't hardcode this
|
||||
60 (Integer/parseInt chod))
|
||||
(catch Exception e
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
MAY CAUSE WRITE TO chod-thread-cache IF NECCESARRY"
|
||||
[board config]
|
||||
(let [refresh-rate (* 1000 (get-in config `(:boards-enabled ~board :refresh-rate)))
|
||||
board-catalog-url (get-in config `(:boards-enabled ~board :target))
|
||||
{data :data
|
||||
time-downloaded :time
|
||||
:or {time-downloaded 0}
|
||||
|
@ -117,5 +118,5 @@
|
|||
time-to-update? (or (nil? board-atom)
|
||||
(> (System/currentTimeMillis) (+ refresh-rate time-downloaded)))]
|
||||
(if time-to-update?
|
||||
(update-board-cache! (get-board-url board config) board (get-in config [:boards-enabled board :starting-page]))
|
||||
(update-board-cache! board-catalog-url board (get-in config [:boards-enabled board :starting-page]))
|
||||
@(get @chod-threads-cache board))))
|
||||
|
|
Loading…
Reference in a new issue