Skip to content

Commit

Permalink
Fix parse description method
Browse files Browse the repository at this point in the history
Fixed #5

Signed-off-by: Yen-Chin Lee <[email protected]>
  • Loading branch information
coldnew committed Apr 9, 2016
1 parent d7d478e commit 87fe586
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
[migratus "0.8.13"]
[environ "1.0.2"]
[im.chit/hara.io.scheduler "2.2.17"]
[im.chit/hara.time.joda "2.2.17"]]
[im.chit/hara.time.joda "2.2.17"]
[enlive "1.1.6"]]

:plugins [[migratus-lein "0.2.6"]]

Expand Down
14 changes: 12 additions & 2 deletions src/clojuretwbot/feed.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns clojuretwbot.feed
(:require [clj-http.client :as http]
[net.cgrand.enlive-html :as html]
[taoensso.timbre :as timbre]
[feedparser-clj.core :as feedparser]
[clojure.string :as str]
Expand All @@ -17,12 +18,21 @@
(catch Exception e
(timbre/warn (.getMessage e)))))

(defn- parse-meta
"Parse HTML content's metadata."
[html property]
(-> html
(java.io.StringReader.)
(html/html-resource)
(html/select [[:meta (html/attr= :property property)]])
(first)
(get-in [:attrs :content])))

(defn- parse-description
"Parse feed's og:description info, set :description to nil if not exist."
[info]
(let [html (or (fetch-html (:link info)) "")
description (-> (re-find #"(<meta\s*property=\"og:description\"\s*content=\")(.*)(\">)" html)
(nth 2))]
description (parse-meta html "og:description")]
(merge info {:description description})))

(defn- parse-feed
Expand Down

0 comments on commit 87fe586

Please sign in to comment.