1 ;;; nnrss.el --- interfacing with RSS
2 ;; Copyright (C) 2001 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
42 ;; Report failure to find w3 at load time if appropriate.
43 (eval '(require 'xml))
47 (defvoo nnrss-directory (nnheader-concat gnus-directory "rss/")
48 "Where nnrss will save its files.")
50 ;; (group max rss-url)
51 (defvoo nnrss-server-data nil)
53 ;; (num timestamp url subject author date extra)
54 (defvoo nnrss-group-data nil)
55 (defvoo nnrss-group-max 0)
56 (defvoo nnrss-group-min 1)
57 (defvoo nnrss-group nil)
58 (defvoo nnrss-group-hashtb nil)
59 (defvoo nnrss-status-string "")
61 (defconst nnrss-version "nnrss 1.0")
63 (defvar nnrss-group-alist
65 "http://macweek.zdnet.com/macweek.xml"
66 "The Macintosh news authority.")
68 "http://lwn.net/headlines/rss")
70 "http://www.fool.com/About/headlines/rss_headlines.asp")
72 "http://www.newsforge.com/newsforge.rdf")
74 "http://www.slashdot.com/slashdot.rdf")
76 "http://www.cnn.com/cnn.rss"
77 "The world's news leader.")
79 "http://freshmeat.net/backend/fm-releases.rdf"
80 "The one-stop-shop for all your Linux software needs.")
81 ("The.Guardian.newspaper"
82 "http://www.guardianunlimited.co.uk/rss/1,,,00.xml"
83 "Intelligent news and comment throughout the day from The Guardian newspaper.")
85 "http://monkeyfist.com/rdf.php3"
86 "News and opinion on politics, technology, and eclectic miscellany.")
88 "http://www.newsforge.com/newsforge.rss")
90 "http://www.reutershealth.com/eline.rss"
91 "Consumer-oriented health-related news stories.")
93 "http://www.salon.com/feed/RDF/salon_use.rdf")
95 "http://www.wired.com/news_drop/netcenter/netcenter.rdf")
97 "http://www.itn.co.uk/itn.rdf")
99 "http://www.oreillynet.com/meerkat/?_fl=rss10"
100 "An Open Wire Service")
102 "http://monkeyfist.com/rss1.php3"
103 "News and opinion on politics, technology, and eclectic miscellany.")
104 ("Reuters.Health.rdf"
105 "http://www.reutershealth.com/eline.rdf"
106 "Consumer-oriented health-related news stories.")
107 ;;("4xt" "http://4xt.org/news/general.rss10" "Resources for XT users.")
108 ("Aaronland" "http://aaronland.net/xml/abhb.rdf" "A boy and his basement.")
109 ("Art of the Mix" "http://www.artofthemix.org/xml/rss.asp" "A website devoted to the art of making mixed tapes and cds.")
110 ("Dave Beckett's RDF Resource Guide" "http://www.ilrt.bristol.ac.uk/discovery/rdf/resources/rss.rdf" "A comprehensive guide to resources about RDF.")
111 ("David Chess" "http://www.davidchess.com/words/log.rss" "Mostly-daily musings on philosophy, children, culture, technology, the emergence of life from matter, chocolate, Nomic, and all that sort of thing.")
112 ;;("Dublin Core Metadata Intitiative" "http://www.dublincore.org/news.rss" "Latest news from DCMI.")
113 ("Figby Articles" "http://www.figby.com/index-rss.php" "A weblog with daily stories about technology, books and publishing, privacy, science, and occasional humor.")
114 ;;("Figby News" "http://www.figby.com/news.php" "Categorized RSS feeds from various sources.")
115 ("Figby Quickies" "http://www.figby.com/quickies-rss.php" "Quick commented links to other sites from Figby.com.")
116 ("Flutterby!" "http://www.flutterby.com/main.rdf" "News and views from Dan Lyke.")
117 ("Groovelog" "http://groovelog.agora.co.uk/groove+log/groovelog.nsf/today.rss.xml" "The open-access groove users' weblog.")
118 ;;("Groovelog.rss10" "http://groovelog.agora.co.uk/groove+log/groovelog.nsf/today.rss10.xml" "The open-access groove users' weblog.")
119 ("Hit or Miss" "http://hit-or-miss.org/rss/" "Daily weblog and journal.")
120 ;;("Internet.com Feeds" "http://www.webreference.com/services/news/" "News from ")
121 ("Larkfarm News" "http://www.larkfarm.com/Larkfarm.rdf" "Mike Gunderloy's web site.")
122 ("Latest RFCs" "http://x42.com/rss/rfc.rss")
123 ("Linux Today" "http://linuxtoday.com/backend/biglt.rss")
124 ("Linux Today.rdf" "http://linuxtoday.com/backend/my-netscape10.rdf")
125 ("More Like This WebLog" "http://www.whump.com/moreLikeThis/RSS" "Because the more you know, the more jokes you get.")
126 ("Motivational Quotes of the Day" "http://www.quotationspage.com/data/mqotd.rss" "Four motivational quotations each day from the Quotations Page.")
127 ;;("My Netscape Network" "http://www.dmoz.org/Netscape/My_Netscape_Network/")
128 ;;("My UserLand" "http://my.userland.com/choose")
129 ("Network World Fusion NetFlash" "http://www.nwfusion.com/netflash.rss" "Daily breaking news about networking products, technologies and services.")
130 ;;("News Feeds" "http://newsfeeds.manilasites.com/" "Jeff Barr highlights high quality RSS feeds.")
131 ;;("News Is Free Export" "http://www.newsisfree.com/export.php3")
132 ("News Is Free" "http://www.newsisfree.com/news.rdf.php3")
133 ;;("News is Free XML Export" "http://www.newsisfree.com/ocs/directory.xml")
134 ("O'Reilly Network Articles" "http://www.oreillynet.com/cs/rss/query/q/260?x-ver=1.0")
135 ("Quotes of the Day" "http://www.quotationspage.com/data/qotd.rss" "Four humorous quotations each day from the Quotations Page.")
136 ("RDF Interest Group" "http://ilrt.org/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=www-rdf-interest" "An experimental channel scraped from the RDF Interest Group mail archives.")
137 ("RDF Logic List" "http://ilrt.org/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=www-rdf-logic" "An experimental channel scraped from the RDF Logic mail archives.")
138 ("RSS Info" "http://www.blogspace.com/rss/rss10" "News and information on the RSS format")
139 ;;("RSS-DEV listing" "http://www.egroups.com/links/rss-dev/Feeds_000966335046/" "A listing of RSS files from the RSS-DEV list.")
140 ("Semantic Web List" "http://ilrt.org/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=semantic-web" "An experimental channel scraped from the W3C's Semantic Web mail archives.")
141 ;;("Sherch!" "http://www.sherch.com/~pldms/cgi-bin/sherch.pl" "Sherlock for the rest of us.")
142 ;;("Street Fusion Archived Financial Webcasts" "http://partners.streetfusion.com/rdf/archive.rdf")
143 ;;("Street Fusion Upcoming Financial Webcasts" "http://partners.streetfusion.com/rdf/live.rdf")
144 ;;("TNL.net newsletter" "http://www.tnl.net/newsletter/channel100.asp" "A newsletter about Internet technology and issues.")
145 ("W3C" "http://www.w3.org/2000/08/w3c-synd/home.rss" "The latest news at the World Wide Web Consortium.")
146 ;;("XML News: RSS Live Content" "http://www.xmlnews.org/RSS/content.html" "A listing of well-known RSS feeds.")
147 ("|fr| XMLfr" "http://xmlfr.org/actualites/general.rss10"
148 "French speaking portal site dedicated to XML.")
149 ("XMLhack" "http://xmlhack.com/rss10.php"
150 "Developer news from the XML community.")
152 "http://www.theregister.co.uk/tonys/slashdot.rdf"
153 "The Register -- Biting the hand that feeds IT.")
155 "http://www.heise.de/newsticker/heise.rdf"
156 "German news ticker about technology.")
157 ("|de| Telepolis News"
158 "http://www.heise.de/tp/news.rdf"
159 "German background news about technology.")
161 "http://www.kuro5hin.org/backend.rdf"
162 "Technology and culture, from the trenches.")
164 "http://www.jabbercentral.com/rss.php"
165 "News around the Jabber instant messaging system.")))
167 (defvar nnrss-use-local nil)
169 (defvar nnrss-description-field 'X-Gnus-Description
170 "Field name used for DESCRIPTION.
171 To use the description in headers, put this name into `nnmail-extra-headers'.")
173 (defvar nnrss-url-field 'X-Gnus-Url
174 "Field name used for URL.
175 To use the description in headers, put this name into `nnmail-extra-headers'.")
177 (nnoo-define-basics nnrss)
179 ;;; Interface functions
181 (deffoo nnrss-retrieve-headers (articles &optional group server fetch-old)
182 (nnrss-possibly-change-group group server)
185 (set-buffer nntp-server-buffer)
187 (dolist (article articles)
188 (if (setq e (assq article nnrss-group-data))
189 (insert (number-to-string (car e)) "\t" ;; number
191 (nnrss-format-string (nth 3 e)) "")
194 (nnrss-format-string (nth 4 e))
199 (format "<%d@%s.nnrss>" (car e) group)
206 (memq nnrss-description-field
207 nnmail-extra-headers))
208 (concat (symbol-name nnrss-description-field)
210 (nnrss-format-string (nth 6 e))
214 (memq nnrss-url-field
215 nnmail-extra-headers))
216 (concat (symbol-name nnrss-url-field)
218 (nnrss-format-string (nth 2 e))
224 (deffoo nnrss-request-group (group &optional server dont-check)
225 (nnrss-possibly-change-group group server)
228 (nnrss-check-group group server)
229 (nnheader-report 'nnrss "Opened group %s" group)
231 "211 %d %d %d %s\n" nnrss-group-max nnrss-group-min nnrss-group-max
232 (prin1-to-string group)
235 (deffoo nnrss-close-group (group &optional server)
238 (deffoo nnrss-request-article (article &optional group server buffer)
239 (nnrss-possibly-change-group group server)
240 (let ((e (assq article nnrss-group-data))
241 (nntp-server-buffer (or buffer nntp-server-buffer))
245 (with-current-buffer nntp-server-buffer
247 (goto-char (point-min))
249 (insert "Newsgroups: " group "\n"))
251 (insert "Subject: " (nnrss-format-string (nth 3 e)) "\n"))
253 (insert "From: " (nnrss-format-string (nth 4 e)) "\n"))
255 (insert "Date: " (nnrss-format-string (nth 5 e)) "\n"))
256 (insert "Message-ID: " (format "<%d@%s.nnrss>" (car e) group) "\n")
259 (let ((point (point)))
260 (insert (nnrss-string-as-multibyte (nth 6 e)))
262 (while (search-forward "\n" nil t)
264 (goto-char (point-max))
266 (fill-region point (point))))
268 (insert (nth 2 e) "\n")))))
271 (nnheader-report 'nnrss err))
273 (nnheader-report 'nnrss "No such id: %d" article))
275 (nnheader-report 'nnrss "Article %s retrieved" (car e))
276 ;; We return the article number.
277 (cons nnrss-group (car e))))))
279 (deffoo nnrss-request-list (&optional server)
280 (nnrss-possibly-change-group nil server)
281 (nnrss-generate-active)
284 (deffoo nnrss-open-server (server &optional defs connectionless)
285 (nnrss-read-server-data server)
286 (nnoo-change-server 'nnrss server defs)
289 (deffoo nnrss-request-expire-articles
290 (articles group &optional server force)
291 (nnrss-possibly-change-group group server)
292 (let (e days not-expirable changed)
293 (dolist (art articles)
294 (if (and (setq e (assq art nnrss-group-data))
295 (nnmail-expired-article-p
297 (if (listp (setq days (nth 1 e))) days
298 (days-to-time (- days (time-to-days '(0 0)))))
300 (setq nnrss-group-data (delq e nnrss-group-data)
302 (push art not-expirable)))
304 (nnrss-save-group-data group server))
307 (deffoo nnrss-request-delete-group (group &optional force server)
308 (nnrss-possibly-change-group group server)
309 (setq nnrss-server-data
310 (delq (assoc group nnrss-server-data) nnrss-server-data))
311 (nnrss-save-server-data server)
312 (let ((file (expand-file-name
313 (nnrss-translate-file-chars
314 (concat group (and server
315 (not (equal server ""))
317 server ".el")) nnrss-directory)))
322 (deffoo nnrss-request-list-newsgroups (&optional server)
323 (nnrss-possibly-change-group nil server)
325 (set-buffer nntp-server-buffer)
327 (dolist (elem nnrss-group-alist)
329 (insert (car elem) "\t" (third elem) "\n"))))
332 (nnoo-define-skeleton nnrss)
334 ;;; Internal functions
336 (defun nnrss-possibly-change-group (&optional group server)
338 (not (nnrss-server-opened server)))
339 (nnrss-open-server server))
340 (when (and group (not (equal group nnrss-group)))
341 (nnrss-read-group-data group server)
342 (setq nnrss-group group)))
344 (defvar nnrss-extra-categories '(nnrss-snarf-moreover-categories))
346 (defun nnrss-generate-active ()
347 (if (y-or-n-p "Fetch extra categories? ")
348 (dolist (func nnrss-extra-categories)
351 (set-buffer nntp-server-buffer)
353 (dolist (elem nnrss-group-alist)
354 (insert (prin1-to-string (car elem)) " 0 1 y\n"))
355 (dolist (elem nnrss-server-data)
356 (unless (assoc (car elem) nnrss-group-alist)
357 (insert (prin1-to-string (car elem)) " 0 1 y\n")))))
361 (defun nnrss-read-server-data (server)
362 (setq nnrss-server-data nil)
363 (let ((file (expand-file-name
364 (nnrss-translate-file-chars
365 (concat "nnrss" (and server
366 (not (equal server ""))
371 (when (file-exists-p file)
373 (let ((coding-system-for-read 'binary)
374 emacs-lisp-mode-hook)
375 (insert-file-contents file)
377 (goto-char (point-min))
380 (defun nnrss-save-server-data (server)
381 (gnus-make-directory nnrss-directory)
382 (let ((file (expand-file-name
383 (nnrss-translate-file-chars
384 (concat "nnrss" (and server
385 (not (equal server ""))
389 (let ((coding-system-for-write 'binary)
390 print-level print-length)
392 (insert "(setq nnrss-server-data '"
393 (prin1-to-string nnrss-server-data)
396 (defun nnrss-read-group-data (group server)
397 (setq nnrss-group-data nil)
398 (setq nnrss-group-hashtb (gnus-make-hashtable))
399 (let ((pair (assoc group nnrss-server-data)))
400 (setq nnrss-group-max (or (cadr pair) 0))
401 (setq nnrss-group-min (+ nnrss-group-max 1)))
402 (let ((file (expand-file-name
403 (nnrss-translate-file-chars
404 (concat group (and server
405 (not (equal server ""))
409 (when (file-exists-p file)
411 (let ((coding-system-for-read 'binary)
412 emacs-lisp-mode-hook)
413 (insert-file-contents file)
415 (goto-char (point-min))
417 (dolist (e nnrss-group-data)
418 (gnus-sethash (nth 2 e) e nnrss-group-hashtb)
419 (if (and (car e) (> nnrss-group-min (car e)))
420 (setq nnrss-group-min (car e)))
421 (if (and (car e) (< nnrss-group-max (car e)))
422 (setq nnrss-group-max (car e)))))))
424 (defun nnrss-save-group-data (group server)
425 (gnus-make-directory nnrss-directory)
426 (let ((file (expand-file-name
427 (nnrss-translate-file-chars
428 (concat group (and server
429 (not (equal server ""))
433 (let ((coding-system-for-write 'binary)
434 print-level print-length)
436 (insert "(setq nnrss-group-data '"
437 (prin1-to-string nnrss-group-data)
442 (defun nnrss-no-cache (url)
445 (defun nnrss-insert-w3 (url)
446 (mm-with-unibyte-current-buffer
447 (mm-url-insert url)))
449 (defun nnrss-decode-entities-unibyte-string (string)
450 (mm-with-unibyte-buffer
452 (mm-url-decode-entities-nbsp)
453 (buffer-substring (point-min) (point-max))))
455 (defalias 'nnrss-insert 'nnrss-insert-w3)
457 (if (featurep 'xemacs)
458 (defalias 'nnrss-string-as-multibyte 'identity)
459 (defalias 'nnrss-string-as-multibyte 'string-as-multibyte))
463 (defun nnrss-check-group (group server)
464 (let (file xml subject url extra changed author date)
466 (mm-with-unibyte-buffer
467 (if (and nnrss-use-local
468 (file-exists-p (setq file (expand-file-name
469 (nnrss-translate-file-chars
470 (concat group ".xml"))
472 (insert-file-contents file)
473 (setq url (or (nth 2 (assoc group nnrss-server-data))
474 (second (assoc group nnrss-group-alist))))
477 (read-string (format "RSS url of %s: " group "http://")))
478 (let ((pair (assoc group nnrss-server-data)))
480 (setcdr (cdr pair) (list url))
481 (push (list group nnrss-group-max url) nnrss-server-data)))
484 (goto-char (point-min))
485 (while (re-search-forward "\r\n?" nil t)
486 (replace-match "\n"))
487 (goto-char (point-min))
488 (if (re-search-forward "<rdf\\|<rss" nil t)
489 (goto-char (match-beginning 0)))
490 (setq xml (xml-parse-region (point) (point-max))))
492 (nnheader-message 1 "Error in group %s: %s" group (cadr err))))
493 (while (and xml (not (assq 'item xml)))
494 (unless (listp (car (setq xml (cddar xml))))
496 (dolist (item (nreverse xml))
497 (when (and (listp item)
498 (eq 'item (car item))
499 (setq url (nnrss-node-text (assq 'link (cddr item))))
500 (setq url (nnrss-decode-entities-unibyte-string url))
501 (not (gnus-gethash url nnrss-group-hashtb)))
502 (setq subject (nnrss-node-text (assq 'title (cddr item))))
503 (setq extra (or (nnrss-node-text (assq 'description (cddr item)))
504 (nnrss-node-text (assq 'dc:description (cddr item)))))
505 (setq author (nnrss-node-text (assq 'dc:creator (cddr item))))
506 (setq date (or (nnrss-node-text (assq 'dc:date (cddr item)))
507 (message-make-date)))
510 (incf nnrss-group-max)
513 (and subject (nnrss-decode-entities-unibyte-string subject))
514 (and author (nnrss-decode-entities-unibyte-string author))
516 (and extra (nnrss-decode-entities-unibyte-string extra)))
518 (gnus-sethash url (car nnrss-group-data) nnrss-group-hashtb)
521 (nnrss-save-group-data group server)
522 (let ((pair (assoc group nnrss-server-data)))
524 (setcar (cdr pair) nnrss-group-max)
525 (push (list group nnrss-group-max) nnrss-server-data)))
526 (nnrss-save-server-data server))))
528 (defun nnrss-generate-download-script ()
529 "Generate a download script in the current buffer.
530 It is useful when `(setq nnrss-use-local t)'."
532 (insert "#!/bin/sh\n")
533 (insert "WGET=wget\n")
534 (insert "RSSDIR='" (expand-file-name nnrss-directory) "'\n")
535 (dolist (elem nnrss-server-data)
536 (let ((url (or (nth 2 elem)
537 (second (assoc (car elem) nnrss-group-alist)))))
538 (insert "$WGET -q -O \"$RSSDIR\"/'"
539 (nnrss-translate-file-chars (concat (car elem) ".xml"))
542 (defun nnrss-translate-file-chars (name)
543 (let ((nnheader-file-name-translation-alist
544 (append nnheader-file-name-translation-alist '((?' . ?_)))))
545 (nnheader-translate-file-chars name)))
547 (defvar nnrss-moreover-url
548 "http://w.moreover.com/categories/category_list_rss.html"
549 "The url of moreover.com categories.")
551 (defun nnrss-snarf-moreover-categories ()
552 "Snarf RSS links from moreover.com."
554 (let (category name url changed)
556 (nnrss-insert nnrss-moreover-url)
557 (goto-char (point-min))
558 (while (re-search-forward
559 "<A NAME=\"\\([^\"]+\\)\">\\|<A HREF=\"\\(http://[^\"]*moreover\\.com[^\"]+page\\?c=\\([^\"&]+\\)&o=rss\\)" nil t)
561 (setq category (match-string 1))
562 (setq url (match-string 2)
563 name (mm-url-decode-entities-string
564 (rfc2231-decode-encoded-string
567 (setq name (concat category "." name)))
568 (unless (assoc name nnrss-server-data)
570 (push (list name 0 url) nnrss-server-data)))))
572 (nnrss-save-server-data ""))))
574 (defun nnrss-format-string (string)
575 (gnus-replace-in-string (nnrss-string-as-multibyte string) " *\n *" " "))
577 (defun nnrss-node-text (node)
578 (if (and node (listp node))
579 (mapconcat 'nnrss-node-text (cddr node) "")
584 ;;; nnrss.el ends here