Skip to content

Commit

Permalink
Fixed issue where parsing to a single format was failing. Now try a b…
Browse files Browse the repository at this point in the history
…unch of formats until one unparses, then parset to compact form
  • Loading branch information
Aria Haghighi committed Nov 1, 2010
1 parent 31d1ed0 commit dfd6190
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/webmine/feeds.clj
Expand Up @@ -20,6 +20,18 @@
java.io.InputStream))


(defn- compact-date-time [s]
(let [date-time
(first
(filter identity
(map
(fn [f]
(try
(time-fmt/parse f s)
(catch Exception _ nil)))
(vals time-fmt/formatters))))]
(time-fmt/unparse (time-fmt/formatters :date-time) date-time)))

(defn- item-node-to-entry [item]
(let [item-root (zip/xml-zip item)
get-text (fn [k] (xml-zip/xml1-> item-root k xml-zip/text))]
Expand All @@ -31,8 +43,7 @@
(map get-text [:description :content :content:encoded])))
:date (first (for [k [:pubDate :date :updatedDate]
:let [s (get-text k)]
:when k] (time-fmt/unparse (time-fmt/formatters :date-time)
s)))
:when k] (compact-date-time s)))
:author (get-text :author)}))

(defn- str-to-url [s]
Expand Down Expand Up @@ -221,4 +232,7 @@ May not be a good idea for blogs that have many useful feeds, for example, for a

(comment
(entries "http://www.rollingstone.com/siteServices/rss/allNews")
(entries (java.net.URL. "http://www.rollingstone.com/siteServices/rss/allNews"))
)


0 comments on commit dfd6190

Please sign in to comment.