Permalink
Browse files

support for parsing input streams, not just urls

  • Loading branch information...
1 parent c91d814 commit f6180428f5ad11ea2183df27e43fe47f332ecece @vgeshel vgeshel committed Oct 9, 2011
Showing with 15 additions and 8 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 project.clj
  3. +13 −7 src/feedparser_clj/core.clj
View
@@ -0,0 +1 @@
+/lib/
View
@@ -1,4 +1,4 @@
-(defproject feedparser-clj "0.2"
+(defproject feedparser-clj "0.3"
:description "Parse RSS/Atom feeds with a simple, clojure-friendly API."
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
@@ -82,16 +82,22 @@
:title (.getTitle f)
:uri (.getUri f)))
-(defn parse-feed "Get and parse a feed from a URL"
- [feedurl]
+(defn- parse-internal [xmlreader]
(let [feedinput (new SyndFeedInput)
- xmlreader (new XmlReader (new URL feedurl))
syndfeed (.build feedinput xmlreader)]
(make-feed syndfeed)))
+(defn parse-feed "Get and parse a feed from a URL"
+ ([feedsource]
+ (parse-internal (new XmlReader (if (string? feedsource)
+ (URL. feedsource)
+ feedsource))))
+ ([feedsource content-type]
+ (parse-internal (new XmlReader feedsource content-type))))
+
(defn -main "Show basic information for a feed, given a URL"
- [feedurl]
- (println "Using feed:" feedurl)
- (let [myfeed (parse-feed feedurl)]
+ [feedsource]
+ (println "Using feed:" feedsource)
+ (let [myfeed (parse-feed feedsource)]
(println "Found" (count (:entries myfeed)) "entries")
- (println myfeed)))
+ (println myfeed)))

0 comments on commit f618042

Please sign in to comment.