Created
April 28, 2020 19:07
-
-
Save 7even/75f06e61cbc9c229748577de4a338d69 to your computer and use it in GitHub Desktop.
Meduza RSS parser in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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