/
normal.clj
33 lines (31 loc) · 1.29 KB
/
normal.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns super-rss.impl.normal
(:require [clojure.string :as string]
[clojure.tools.logging :as log]
[net.cgrand.enlive-html :as html]
[remus :as remus]
[super-rss.html :as rss.html]
[super-rss.util :as util]))
(defn find-feed-url
[website-url]
(let [content (rss.html/get-web-page website-url)
feed-url (->> (html/select content [:link])
(filter #(get #{"application/atom+xml" "application/rss+xml" "text/xml"}
(get-in % [:attrs :type])))
first
:attrs :href)]
(when feed-url
(util/url->absolute-url (util/get-base-url website-url) feed-url))))
(defn fetch-rss
"Fetch feed, works with all RSS format"
[url timeout]
(try
(let [{:keys [feed]} (remus/parse-url url {:insecure? true
:connection-timeout timeout})]
{:title (some-> (:title feed) (string/trim))
:description (some-> (:description feed) (string/trim))
:entries (:entries feed)})
(catch clojure.lang.ExceptionInfo e
(let [response (ex-data e)]
(log/errorf "Fail to fetch url %s %s" url response)))
(catch Exception e
(log/errorf e "Fail to fetch url %s" url))))