Implement support for multiple filters
Allows for adding more filters so regex or searching by thread number will be much easier
This commit is contained in:
parent
18cc3e730c
commit
1890f14f9e
1 changed files with 17 additions and 22 deletions
|
@ -69,9 +69,8 @@
|
||||||
|
|
||||||
(defn filter-chod-posts
|
(defn filter-chod-posts
|
||||||
"Return list of all threads with equal or higher ChoD than requested
|
"Return list of all threads with equal or higher ChoD than requested
|
||||||
;;resume
|
|
||||||
READS FROM GLOBALS: watcher.time-of-cache"
|
READS FROM GLOBALS: watcher.time-of-cache"
|
||||||
[query-vec chod-treshold repeat? board-cache]
|
[filters chod-treshold repeat? board-cache]
|
||||||
(let [{time-of-generation :time
|
(let [{time-of-generation :time
|
||||||
cache :data} board-cache
|
cache :data} board-cache
|
||||||
guid-fn (case repeat?
|
guid-fn (case repeat?
|
||||||
|
@ -82,25 +81,21 @@
|
||||||
cache))
|
cache))
|
||||||
;; So we don't have to search thru everything we have cached
|
;; So we don't have to search thru everything we have cached
|
||||||
needed-cache-part (subvec cache cache-start-index)
|
needed-cache-part (subvec cache cache-start-index)
|
||||||
;; Here we gonna run fmap but not really
|
actuall-matches (keep (fn [thread]
|
||||||
actuall-matches (keep (fn [t]
|
(some
|
||||||
(let [title (:title t)]
|
(fn [fun]
|
||||||
;; Todo: Man, wouldn't it be cool to know which querry matched the thread?
|
(when (fun thread (get filters fun))
|
||||||
;; Would be so much easier for user to figure out why is it showing
|
thread))
|
||||||
;; and it would solve the problem of super long titles (or OPs instead of titles)
|
(keys filters)))
|
||||||
(when (some (fn [querry]
|
|
||||||
(s/includes? (s/lower-case title) (s/lower-case querry)))
|
|
||||||
query-vec)
|
|
||||||
t)))
|
|
||||||
(reverse needed-cache-part))]
|
(reverse needed-cache-part))]
|
||||||
;; Finally generate and append GUIDs
|
;; Finally generate and append GUIDs
|
||||||
(map guid-fn actuall-matches)))
|
(map guid-fn actuall-matches)))
|
||||||
|
|
||||||
(defn thread-to-rss-item
|
(defn thread-to-rss-item
|
||||||
"Converts cached thread item to feed item which can be serialized into RSS"
|
"Converts cached thread item to feed item which can be serialized into RSS"
|
||||||
[t host board]
|
[t host]
|
||||||
(let [link-url (s/replace host "{threadnum}" (str (:no t)))] ;Hardcode emergency bugfix
|
(let [link-url (s/replace host "{threadnum}" (str (:no t)))]
|
||||||
{:title (format "%.2f%% - %s" (:chod t) (:title t)) ;TODO: Generate link from the target somehow, or just include it from API response
|
{:title (format "%.2f%% - %s" (:chod t) (:title t))
|
||||||
;; :url link-url <- this is supposed to be for images according to: https://cyber.harvard.edu/rss/rss.html
|
;; :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))
|
:description (format "The thread: '%s' has %.2f%% chance of dying" (:title t) (:chod t))
|
||||||
:link link-url
|
:link link-url
|
||||||
|
@ -108,9 +103,8 @@
|
||||||
|
|
||||||
(defn generate-feed
|
(defn generate-feed
|
||||||
"Generates feed from matching items"
|
"Generates feed from matching items"
|
||||||
[query-vec chod-treshold repeat? cache board-config self-link]
|
[filters chod-treshold repeat? cache board-config self-link]
|
||||||
(let [items (filter-chod-posts query-vec chod-treshold repeat? cache)
|
(let [items (filter-chod-posts filters chod-treshold repeat? cache)
|
||||||
served-filename (get @conf/GLOBAL-CONFIG :served-filename)
|
|
||||||
head {:title (str "RSS Thread watcher v" conf/VERSION)
|
head {:title (str "RSS Thread watcher v" conf/VERSION)
|
||||||
;; :link is the homepage of the channel
|
;; :link is the homepage of the channel
|
||||||
:link (get @conf/GLOBAL-CONFIG :homepage)
|
:link (get @conf/GLOBAL-CONFIG :homepage)
|
||||||
|
@ -141,9 +135,10 @@
|
||||||
query :query-string
|
query :query-string
|
||||||
scheme :scheme
|
scheme :scheme
|
||||||
server-name :server-name} rqst
|
server-name :server-name} rqst
|
||||||
filters (make-filters prms)
|
filters (make-filters prms f/known-filters)
|
||||||
;; qrs (prms "q")
|
;; BUG if local fileserver not running -> FileNotFound exception is thrown and it fucks up the feed generation
|
||||||
self-uri (str (s/replace-first scheme ":" "")
|
;; Should be handled because wrong config and thus url generation could do the same
|
||||||
|
self-uri (str (s/replace-first scheme ":" "") ;
|
||||||
"://" server-name uri "?" query)
|
"://" server-name uri "?" query)
|
||||||
board-config (get-in @conf/GLOBAL-CONFIG [:boards-enabled board])
|
board-config (get-in @conf/GLOBAL-CONFIG [:boards-enabled board])
|
||||||
real-chod (try (max (Integer/parseInt (or (and (vector? chod)
|
real-chod (try (max (Integer/parseInt (or (and (vector? chod)
|
||||||
|
@ -187,7 +182,7 @@
|
||||||
;; There shouldn't be any problems with this mime type but if there are
|
;; 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
|
;; replace with "text/xml", or even better, get RSS reader that is not utter shit
|
||||||
:header {"Content-Type" "application/rss+xml"}
|
:header {"Content-Type" "application/rss+xml"}
|
||||||
:body (generate-feed queries real-chod repeat? (watcher/get-thread-data board @conf/GLOBAL-CONFIG) board-config self-uri)})
|
:body (generate-feed filters real-chod repeat? (watcher/get-thread-data board @conf/GLOBAL-CONFIG) board-config self-uri)})
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
;; Ex-info has been crafted to match HTTP response body so we can send it
|
;; Ex-info has been crafted to match HTTP response body so we can send it
|
||||||
(if-let [caught (ex-data e)]
|
(if-let [caught (ex-data e)]
|
||||||
|
|
Loading…
Reference in a new issue