Last active
December 21, 2015 05:19
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; 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