Function: newsticker--parse-generic-items
newsticker--parse-generic-items is a byte-compiled function defined in
newst-backend.el.gz.
Signature
(newsticker--parse-generic-items NAME TIME ITEMLIST TITLE-FN DESC-FN LINK-FN TIME-FN GUID-FN EXTRA-FN)
Documentation
Parse generic news feed data.
Argument NAME gives the name of a news feed. TIME gives the system time at which the data have been retrieved. ITEMLIST contains the news items returned by the xml parser.
The arguments TITLE-FN, DESC-FN, LINK-FN, TIME-FN, GUID-FN, and EXTRA-FN give functions for extracting title, description, link, time, guid, and extra-elements resp. They are called with one argument, which is one of the items in ITEMLIST.
Source Code
;; Defined in /usr/src/emacs/lisp/net/newst-backend.el.gz
(defun newsticker--parse-generic-items (name time itemlist
title-fn desc-fn
link-fn time-fn
guid-fn extra-fn)
"Parse generic news feed data.
Argument NAME gives the name of a news feed. TIME gives the
system time at which the data have been retrieved. ITEMLIST
contains the news items returned by the xml parser.
The arguments TITLE-FN, DESC-FN, LINK-FN, TIME-FN, GUID-FN, and
EXTRA-FN give functions for extracting title, description, link,
time, guid, and extra-elements resp. They are called with one
argument, which is one of the items in ITEMLIST."
(let ((position 0)
(something-was-added nil))
;; gather all items for this feed
(dolist (node itemlist)
(setq position (1+ position))
(let ((title (or (funcall title-fn node) "[untitled]"))
(desc (funcall desc-fn node))
(link (or (funcall link-fn node) "")))
(setq time (or (funcall time-fn node) time))
;; It happened that the title or description
;; contained evil HTML code that confused the
;; xml parser. Therefore:
(unless (stringp title)
(setq title (prin1-to-string title)))
(unless (or (stringp desc) (not desc))
(setq desc (prin1-to-string desc)))
;; ignore items with empty title AND empty desc
(when (or (> (length title) 0)
(> (length desc) 0))
;; decode numeric entities
(setq title (xml-substitute-numeric-entities title))
(when desc
(setq desc (xml-substitute-numeric-entities desc)))
(setq link (xml-substitute-numeric-entities link))
;; remove whitespace from title, desc, and link
(setq title (newsticker--remove-whitespace title))
(setq desc (newsticker--remove-whitespace desc))
(setq link (newsticker--remove-whitespace link))
;; add data to cache
;; do we have this item already?
(let ((old-item
(let* ((guid (funcall guid-fn node)))
;;(message "guid=%s" guid)
(newsticker--cache-contains newsticker--cache
(intern name) title
desc link nil guid)))
(age1 'new)
(age2 'old)
(item-new-p nil))
;; Add this item, or mark it as old, or do nothing
(if old-item
(let ((prev-age (newsticker--age old-item)))
(unless newsticker-automatically-mark-items-as-old
;; Some feeds deliver items multiply, the
;; first time we find an 'obsolete-old one in
;; the cache, the following times we find an
;; 'old one
(if (memq prev-age '(obsolete-old old))
(setq age2 'old)
(setq age2 'new)))
(if (eq prev-age 'immortal)
(setq age2 'immortal))
(setq time (newsticker--time old-item)))
;; item was not there
(setq item-new-p t)
(setq something-was-added t))
(let ((extra-elements-with-guid (funcall extra-fn node)))
(unless (assoc 'guid extra-elements-with-guid)
(setq extra-elements-with-guid
(cons `(guid nil ,(funcall guid-fn node))
extra-elements-with-guid)))
(setq newsticker--cache
(newsticker--cache-add
newsticker--cache (intern name) title desc link
time age1 position extra-elements-with-guid
time age2)))
(when item-new-p
(let ((item (newsticker--cache-contains
newsticker--cache (intern name) title
desc link nil)))
(if newsticker-auto-mark-filter-list
(newsticker--run-auto-mark-filter name item))
(run-hook-with-args
'newsticker-new-item-functions name item)))))))
something-was-added))