From f6180428f5ad11ea2183df27e43fe47f332ecece Mon Sep 17 00:00:00 2001 From: Vadim Geshel Date: Sat, 8 Oct 2011 18:21:58 -0700 Subject: [PATCH 1/3] support for parsing input streams, not just urls --- .gitignore | 1 + project.clj | 2 +- src/feedparser_clj/core.clj | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..12c18d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/lib/ diff --git a/project.clj b/project.clj index 6080f48..4e5b3fb 100644 --- a/project.clj +++ b/project.clj @@ -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"] diff --git a/src/feedparser_clj/core.clj b/src/feedparser_clj/core.clj index 854a236..8c776ff 100644 --- a/src/feedparser_clj/core.clj +++ b/src/feedparser_clj/core.clj @@ -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))) \ No newline at end of file + (println myfeed))) From 7d1b974892f995ead5bb001574be594e07e10864 Mon Sep 17 00:00:00 2001 From: Vadim Geshel Date: Sat, 8 Oct 2011 18:23:44 -0700 Subject: [PATCH 2/3] ignore built files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 12c18d4..2968031 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /lib/ +/feedparser-clj-0.3.jar +/pom.xml From d21fb5381499de2bf9501e85124e2250e857a94f Mon Sep 17 00:00:00 2001 From: Vadim Geshel Date: Sat, 8 Oct 2011 18:29:29 -0700 Subject: [PATCH 3/3] changed to my own maven group to allow upload to clojars --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 4e5b3fb..366795b 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject feedparser-clj "0.3" +(defproject org.clojars.vgeshel/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"]