Skip to content

Instantly share code, notes, and snippets.

@7even
Created April 28, 2020 19:07
Show Gist options
  • Save 7even/75f06e61cbc9c229748577de4a338d69 to your computer and use it in GitHub Desktop.
Save 7even/75f06e61cbc9c229748577de4a338d69 to your computer and use it in GitHub Desktop.
Meduza RSS parser in Clojure
(defn find-tag [tag nodes]
(->> nodes
(filter #(= (:tag %) tag))
first))
(defn tag-content [tag nodes]
(-> (find-tag tag nodes)
:content
first))
(defn parse-date [date-str]
(.parse (SimpleDateFormat. "E, dd MMM yyyy HH:mm:ss XX" java.util.Locale/US)
date-str))
(->> (slurp "https://meduza.io/rss/all")
clojure.data.xml/parse-str
:content
first
:content
(filter #(= (:tag %) :item))
(map (fn [{:keys [content]}]
{:title (tag-content :title content)
:link (tag-content :link content)
:image-url (-> (find-tag :enclosure content)
(get-in [:attrs :url]))
:description (tag-content :description content)
:published-at (parse-date (tag-content :pubDate content))})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment