Skip to content

Instantly share code, notes, and snippets.

@tkych
Last active December 21, 2015 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkych/6255855 to your computer and use it in GitHub Desktop.
Save tkych/6255855 to your computer and use it in GitHub Desktop.
Minimum-Feed-Reader, example for cl-feed-parser (https://github.com/tkych/cl-feed-parser)
;;;; Last modified : 2013-08-17 21:01:33 tkych
;; Example for cl-feed-parser (https://github.com/tkych/cl-feed-parser)
;; Usage:
;; ------
;; * (defparameter f "http://www.whitehouse.gov/feed/press")
;; * (show-entry-titles f)
;; * (read-nth-entry 2 f)
;;====================================================================
;; Minimum-Feed-Reader
;;====================================================================
(in-package :cl-user)
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload :cl-feed-parser))
(defpackage #:mini-feed-reader
(:use :cl)
(:export #:show-entry-titles
#:read-nth-entry))
(in-package #:mini-feed-reader)
;;--------------------------------------------------------------------
;; Note:
;; If you make a real feed reader, you should use :etag, :modified or
;; :request-headers for caching.
(let ((cache (make-hash-table :test #'equal)))
(defun parse (feed-spec)
(or (gethash feed-spec cache nil)
(setf (gethash feed-spec cache)
(feed-parser:parse-feed feed-spec)))))
(defun show-entry-titles (feed-spec)
(let ((f (parse feed-spec)))
(loop
:for i :from 0
:for title := (feed-parser:ref f :entries i :title)
:until (null title)
:do (format t "~&[~D]: ~A" i title))))
(defun read-nth-entry (nth feed-spec)
(princ (or (feed-parser:ref (parse feed-spec)
:entries nth :description)
(feed-parser:ref (parse feed-spec)
:entries nth :summary)))
nil)
;;====================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment