Basic Feed generation now working
This commit is contained in:
parent
51345db93f
commit
45d7c671c7
1 changed files with 30 additions and 4 deletions
|
@ -34,7 +34,7 @@
|
|||
|
||||
This is done by always making new GUID - (concat thread-number UNIX-time-of-data-update)"
|
||||
[thread time]
|
||||
(assoc thread guid (str (:no thread)
|
||||
(assoc thread :guid (str (:no thread)
|
||||
"-"
|
||||
time)))
|
||||
|
||||
|
@ -53,12 +53,15 @@
|
|||
(let [time-of-generation (System/currentTimeMillis)
|
||||
guid-fn (if repeat? (fn [x] (new-guid-always x time-of-generation))
|
||||
update-only-guid)
|
||||
cache-start-index (first (indices (fn [x] (>= x chod-treshold))
|
||||
cache-start-index (first (indices (fn [x] (>= (:chod x) chod-treshold))
|
||||
@cache/chod-threads-cache))
|
||||
;; So we don't have to search thru everything we have cached
|
||||
needed-cache-part (subvec @cache/chod-threads-cache cache-start-index)
|
||||
needed-cache-part (subvec @cache/chod-threads-cache cache-start-index) ;Todo: remove that ugly global reference
|
||||
actuall-matches (keep (fn [t]
|
||||
(let [title (:title t)]
|
||||
;; Todo: Man, wouldn't it be cool to know which querry matched the thread?
|
||||
;; Would be so much easier for user to figure out why is it showing
|
||||
;; and it would solve the problem of super long titles (or OPs instead of titles)
|
||||
(when (some (fn [querry]
|
||||
(s/includes? title querry))
|
||||
query-vec)
|
||||
|
@ -67,6 +70,27 @@
|
|||
;; Finally generate and append GUIDs
|
||||
(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]
|
||||
(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))
|
||||
;; :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))
|
||||
:link link-url
|
||||
:guid (:guid t)}))
|
||||
|
||||
(defn generate-feed
|
||||
[query-vec chod-treshold repeat?]
|
||||
(let [items (filter-chod-posts query-vec chod-treshold repeat?)
|
||||
head {:title "RSS Thread watcher v0.1"
|
||||
: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)]
|
||||
(rss/channel-xml head body)))
|
||||
|
||||
(defn http-handler
|
||||
"Handles HTTP requests, returns generated feed
|
||||
|
||||
|
@ -75,6 +99,8 @@
|
|||
rss-thread-watch.core.CONFIG"
|
||||
[rqst]
|
||||
{:status 200
|
||||
:header {"Content-Type" "text/html"}
|
||||
;; 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 "All pony here ^:)"})
|
||||
|
||||
|
|
Loading…
Reference in a new issue