Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

support for parsing input streams, not just urls

  • Loading branch information...
commit f6180428f5ad11ea2183df27e43fe47f332ecece 1 parent c91d814
Vadim Geshel vgeshel authored

Showing 3 changed files with 15 additions and 8 deletions. Show diff stats Hide diff stats

  1. +1 0  .gitignore
  2. +1 1  project.clj
  3. +13 7 src/feedparser_clj/core.clj
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +/lib/
2  project.clj
... ... @@ -1,4 +1,4 @@
1   -(defproject feedparser-clj "0.2"
  1 +(defproject feedparser-clj "0.3"
2 2 :description "Parse RSS/Atom feeds with a simple, clojure-friendly API."
3 3 :dependencies [[org.clojure/clojure "1.2.1"]
4 4 [org.clojure/clojure-contrib "1.2.0"]
20 src/feedparser_clj/core.clj
@@ -82,16 +82,22 @@
82 82 :title (.getTitle f)
83 83 :uri (.getUri f)))
84 84
85   -(defn parse-feed "Get and parse a feed from a URL"
86   - [feedurl]
  85 +(defn- parse-internal [xmlreader]
87 86 (let [feedinput (new SyndFeedInput)
88   - xmlreader (new XmlReader (new URL feedurl))
89 87 syndfeed (.build feedinput xmlreader)]
90 88 (make-feed syndfeed)))
91 89
  90 +(defn parse-feed "Get and parse a feed from a URL"
  91 + ([feedsource]
  92 + (parse-internal (new XmlReader (if (string? feedsource)
  93 + (URL. feedsource)
  94 + feedsource))))
  95 + ([feedsource content-type]
  96 + (parse-internal (new XmlReader feedsource content-type))))
  97 +
92 98 (defn -main "Show basic information for a feed, given a URL"
93   - [feedurl]
94   - (println "Using feed:" feedurl)
95   - (let [myfeed (parse-feed feedurl)]
  99 + [feedsource]
  100 + (println "Using feed:" feedsource)
  101 + (let [myfeed (parse-feed feedsource)]
96 102 (println "Found" (count (:entries myfeed)) "entries")
97   - (println myfeed)))
  103 + (println myfeed)))

0 comments on commit f618042

Please sign in to comment.
Something went wrong with that request. Please try again.