Skip to content

Commit

Permalink
Use XML Zippers for RSS parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
apage43 committed Nov 12, 2012
1 parent 6397644 commit 4fd6b67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion project.clj
Expand Up @@ -5,7 +5,7 @@
:url "http://sam.zoy.org/wtfpl/"} :url "http://sam.zoy.org/wtfpl/"}
:main marky.app :main marky.app
:dependencies [[org.clojure/clojure "1.4.0"] :dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/data.xml "0.0.6"] [org.clojure/data.zip "0.1.1"]
[overtone/at-at "1.0.0"] [overtone/at-at "1.0.0"]
[twitter-api "0.6.13"] [twitter-api "0.6.13"]
[crouton "0.1.1"] [crouton "0.1.1"]
Expand Down
22 changes: 9 additions & 13 deletions src/marky/app.clj
@@ -1,11 +1,12 @@
(ns marky.app (ns marky.app
(:gen-class) (:gen-class)
(:import [javax.xml.transform.stream StreamSource] (:import [org.jsoup Jsoup])
[org.jsoup Jsoup])
(:require [overtone.at-at :as at-] (:require [overtone.at-at :as at-]
[clojure.string :as st] [clojure.string :as st]
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.data.xml :as xml] [clojure.xml :as xml]
[clojure.zip :as zip]
[clojure.data.zip.xml :as zip-xml]
[cheshire.core :as json] [cheshire.core :as json]
[cbdrawer.client :as cb] [cbdrawer.client :as cb]
[cbdrawer.view :as cbv] [cbdrawer.view :as cbv]
Expand Down Expand Up @@ -33,19 +34,14 @@
"The Couchbase Java SDK doesn't like some characters..." "The Couchbase Java SDK doesn't like some characters..."
[s] (st/escape s {\space "_" \newline "_" \return "_"})) [s] (st/escape s {\space "_" \newline "_" \return "_"}))


(defn xml-text [el]
(st/join " " (filter string? (tree-seq :content :content el))))

(defn fetch-rss [url] (defn fetch-rss [url]
(let [sourceid (str "rss=" url) (let [sourceid (str "rss=" url)
parsed (xml/parse (StreamSource. url)) parsed (zip/xml-zip (xml/parse url))
entries (filter #(= :entry (:tag %)) (tree-seq :content :content parsed))] entries (zip-xml/xml-> parsed :entry)]
(for [entry entries] (for [entry entries]
{:source-id sourceid {:source-id sourceid
:item-id (str sourceid ",title=" :item-id (cb-safe (str sourceid ",title="(zip-xml/text (zip-xml/xml1-> entry :title))))
(cb-safe (xml-text (first (filter #(= :title (:tag %)) (:content entry)))))) :body (.text (Jsoup/parse (zip-xml/text (zip-xml/xml1-> entry :content))))})))
:body (.text (Jsoup/parse
(xml-text (first (filter #(= :content (:tag %)) (:content entry))))))})))


(def twitter-status-url "http://api.twitter.com/1/statuses/user_timeline.json") (def twitter-status-url "http://api.twitter.com/1/statuses/user_timeline.json")


Expand Down

0 comments on commit 4fd6b67

Please sign in to comment.