Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / nnrss.el
1 ;;; nnrss.el --- interfacing with RSS
2 ;; Copyright (C) 2001  Free Software Foundation, Inc.
3
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: RSS
6
7 ;; This file is part of GNU Emacs.
8
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.
13
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.
18
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.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29
30 (require 'nnoo)
31 (require 'nnmail)
32 (require 'message)
33 (require 'mm-util)
34 (require 'gnus-util)
35 (require 'time-date)
36 (require 'rfc2231)
37 (eval-when-compile
38   (ignore-errors
39     (require 'xml)
40     (require 'w3)
41     (require 'w3-forms)
42     (require 'nnweb)))
43 ;; Report failure to find w3 at load time if appropriate.
44 (eval '(progn
45          (require 'xml)
46          (require 'w3)
47          (require 'w3-forms)
48          (require 'nnweb)))
49
50 (nnoo-declare nnrss)
51
52 (defvoo nnrss-directory (nnheader-concat gnus-directory "rss/")
53   "Where nnrss will save its files.")
54
55 ;; (group max rss-url)
56 (defvoo nnrss-server-data nil)
57
58 ;; (num timestamp url subject author date extra)
59 (defvoo nnrss-group-data nil)
60 (defvoo nnrss-group-max 0)
61 (defvoo nnrss-group-min 1)
62 (defvoo nnrss-group nil)
63 (defvoo nnrss-group-hashtb nil)
64 (defvoo nnrss-status-string "")
65
66 (defconst nnrss-version "nnrss 1.0")
67
68 (defvar nnrss-group-alist
69   '(("MacWeek"
70      "http://macweek.zdnet.com/macweek.xml"
71      "The Macintosh news authority.")
72     ("Linux.Weekly.News"
73      "http://lwn.net/headlines/rss")
74     ("Motley.Fool"
75      "http://www.fool.com/About/headlines/rss_headlines.asp")
76     ("NewsForge.rdf"
77      "http://www.newsforge.com/newsforge.rdf")
78     ("Slashdot"
79      "http://www.slashdot.com/slashdot.rdf")
80     ("CNN"
81      "http://www.cnn.com/cnn.rss"
82      "The world's news leader.")
83     ("FreshMeat"
84      "http://freshmeat.net/backend/fm-releases.rdf"
85      "The one-stop-shop for all your Linux software needs.")
86     ("The.Guardian.newspaper"
87      "http://www.guardianunlimited.co.uk/rss/1,,,00.xml"
88      "Intelligent news and comment throughout the day from The Guardian newspaper.")
89     ("MonkeyFist.rdf"
90      "http://monkeyfist.com/rdf.php3"
91      "News and opinion on politics, technology, and eclectic miscellany.")
92     ("NewsForge"
93      "http://www.newsforge.com/newsforge.rss")
94     ("Reuters.Health"
95      "http://www.reutershealth.com/eline.rss"
96      "Consumer-oriented health-related news stories.")
97     ("Salon"
98      "http://www.salon.com/feed/RDF/salon_use.rdf")
99     ("Wired"
100      "http://www.wired.com/news_drop/netcenter/netcenter.rdf")
101     ("ITN"
102      "http://www.itn.co.uk/itn.rdf")
103     ("Meerkat"
104      "http://www.oreillynet.com/meerkat/?_fl=rss10"
105      "An Open Wire Service")
106     ("MonkeyFist"
107      "http://monkeyfist.com/rss1.php3"
108      "News and opinion on politics, technology, and eclectic miscellany.")
109     ("Reuters.Health.rdf"
110      "http://www.reutershealth.com/eline.rdf"
111      "Consumer-oriented health-related news stories.")
112     ;;("4xt" "http://4xt.org/news/general.rss10" "Resources for XT users.")
113     ("Aaronland" "http://aaronland.net/xml/abhb.rdf" "A boy and his basement.")
114     ("Art of the Mix" "http://www.artofthemix.org/xml/rss.asp" "A website devoted to the art of making mixed tapes and cds.")
115     ("Dave Beckett's RDF Resource Guide" "http://www.ilrt.bristol.ac.uk/discovery/rdf/resources/rss.rdf" "A comprehensive guide to resources about RDF.")
116     ("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.")
117     ;;("Dublin Core Metadata Intitiative" "http://www.dublincore.org/news.rss" "Latest news from DCMI.")
118     ("Figby Articles" "http://www.figby.com/index-rss.php" "A weblog with daily stories about technology, books and publishing, privacy, science, and occasional humor.")
119     ;;("Figby News" "http://www.figby.com/news.php" "Categorized RSS feeds from various sources.")
120     ("Figby Quickies" "http://www.figby.com/quickies-rss.php" "Quick commented links to other sites from Figby.com.")
121     ("Flutterby!" "http://www.flutterby.com/main.rdf" "News and views from Dan Lyke.")
122     ("Groovelog" "http://groovelog.agora.co.uk/groove+log/groovelog.nsf/today.rss.xml" "The open-access groove users' weblog.")
123     ;;("Groovelog.rss10" "http://groovelog.agora.co.uk/groove+log/groovelog.nsf/today.rss10.xml" "The open-access groove users' weblog.")
124     ("Hit or Miss" "http://hit-or-miss.org/rss/" "Daily weblog and journal.")
125     ;;("Internet.com Feeds" "http://www.webreference.com/services/news/" "News from ")
126     ("Larkfarm News" "http://www.larkfarm.com/Larkfarm.rdf" "Mike Gunderloy's web site.")
127     ("Latest RFCs" "http://x42.com/rss/rfc.rss")
128     ("Linux Today" "http://linuxtoday.com/backend/biglt.rss")
129     ("Linux Today.rdf" "http://linuxtoday.com/backend/my-netscape10.rdf")
130     ("More Like This WebLog" "http://www.whump.com/moreLikeThis/RSS" "Because the more you know, the more jokes you get.")
131     ("Motivational Quotes of the Day" "http://www.quotationspage.com/data/mqotd.rss" "Four motivational quotations each day from the Quotations Page.")
132     ;;("My Netscape Network" "http://www.dmoz.org/Netscape/My_Netscape_Network/")
133     ;;("My UserLand" "http://my.userland.com/choose")
134     ("Network World Fusion NetFlash" "http://www.nwfusion.com/netflash.rss" "Daily breaking news about networking products, technologies and services.")
135     ;;("News Feeds" "http://newsfeeds.manilasites.com/" "Jeff Barr highlights high quality RSS feeds.")
136     ;;("News Is Free Export" "http://www.newsisfree.com/export.php3")
137     ("News Is Free" "http://www.newsisfree.com/news.rdf.php3")
138     ;;("News is Free XML Export" "http://www.newsisfree.com/ocs/directory.xml")
139     ("O'Reilly Network Articles" "http://www.oreillynet.com/cs/rss/query/q/260?x-ver=1.0")
140     ("Quotes of the Day" "http://www.quotationspage.com/data/qotd.rss" "Four humorous quotations each day from the Quotations Page.")
141     ("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.")
142     ("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.")
143     ("RSS Info" "http://www.blogspace.com/rss/rss10" "News and information on the RSS format")
144     ;;("RSS-DEV listing" "http://www.egroups.com/links/rss-dev/Feeds_000966335046/" "A listing of RSS files from the RSS-DEV list.")
145     ("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.")
146     ;;("Sherch!" "http://www.sherch.com/~pldms/cgi-bin/sherch.pl" "Sherlock for the rest of us.")
147     ;;("Street Fusion Archived Financial Webcasts" "http://partners.streetfusion.com/rdf/archive.rdf")
148     ;;("Street Fusion Upcoming Financial Webcasts" "http://partners.streetfusion.com/rdf/live.rdf")
149     ;;("TNL.net newsletter" "http://www.tnl.net/newsletter/channel100.asp" "A newsletter about Internet technology and issues.")
150     ("W3C" "http://www.w3.org/2000/08/w3c-synd/home.rss" "The latest news at the World Wide Web Consortium.")
151     ;;("XML News: RSS Live Content" "http://www.xmlnews.org/RSS/content.html" "A listing of well-known RSS feeds.")
152     ("|fr| XMLfr" "http://xmlfr.org/actualites/general.rss10"
153      "French speaking portal site dedicated to XML.")
154     ("XMLhack" "http://xmlhack.com/rss10.php"
155      "Developer news from the XML community.")
156     ("The Register"
157      "http://www.theregister.co.uk/tonys/slashdot.rdf"
158      "The Register -- Biting the hand that feeds IT.")
159     ("|de| Heise-Ticker"
160      "http://www.heise.de/newsticker/heise.rdf"
161      "German news ticker about technology.")
162     ("|de| Telepolis News"
163      "http://www.heise.de/tp/news.rdf"
164      "German background news about technology.")
165     ("Kuro5hin"
166      "http://www.kuro5hin.org/backend.rdf"
167      "Technology and culture, from the trenches.")
168     ("JabberCentral"
169      "http://www.jabbercentral.com/rss.php"
170      "News around the Jabber instant messaging system.")))
171
172 (defvar nnrss-use-local nil)
173
174 (defvar nnrss-description-field 'X-Gnus-Description
175   "Field name used for DESCRIPTION.
176 To use the description in headers, put this name into `nnmail-extra-headers'.")
177
178 (defvar nnrss-url-field 'X-Gnus-Url
179   "Field name used for URL.
180 To use the description in headers, put this name into `nnmail-extra-headers'.")
181
182 (nnoo-define-basics nnrss)
183
184 ;;; Interface functions
185
186 (deffoo nnrss-retrieve-headers (articles &optional group server fetch-old)
187   (nnrss-possibly-change-group group server)
188   (let (e)
189     (save-excursion
190       (set-buffer nntp-server-buffer)
191       (erase-buffer)
192       (dolist (article articles)
193         (if (setq e (assq article nnrss-group-data))
194             (insert (number-to-string (car e)) "\t" ;; number
195                     (if (nth 3 e)
196                         (nnrss-format-string (nth 3 e)) "")
197                     "\t" ;; subject
198                     (if (nth 4 e)
199                         (nnrss-format-string (nth 4 e))
200                       "(nobody)")
201                     "\t" ;;from
202                     (or (nth 5 e) "")
203                     "\t" ;; date
204                     (format "<%d@%s.nnrss>" (car e) group)
205                     "\t" ;; id
206                     "\t" ;; refs
207                     "-1" "\t" ;; chars
208                     "-1" "\t" ;; lines
209                     "" "\t" ;; Xref
210                     (if (and (nth 6 e)
211                              (memq nnrss-description-field
212                                    nnmail-extra-headers))
213                         (concat (symbol-name nnrss-description-field)
214                                 ": "
215                                 (nnrss-format-string (nth 6 e))
216                                 "\t")
217                       "")
218                     (if (and (nth 2 e)
219                              (memq nnrss-url-field
220                                    nnmail-extra-headers))
221                         (concat (symbol-name nnrss-url-field)
222                                 ": "
223                                 (nnrss-format-string (nth 2 e))
224                                 "\t")
225                       "")
226                     "\n")))))
227   'nov)
228
229 (deffoo nnrss-request-group (group &optional server dont-check)
230   (nnrss-possibly-change-group group server)
231   (if dont-check
232       t
233     (nnrss-check-group group server)
234     (nnheader-report 'nnrss "Opened group %s" group)
235     (nnheader-insert
236      "211 %d %d %d %s\n" nnrss-group-max nnrss-group-min nnrss-group-max
237      (prin1-to-string group)
238      t)))
239
240 (deffoo nnrss-close-group (group &optional server)
241   t)
242
243 (deffoo nnrss-request-article (article &optional group server buffer)
244   (nnrss-possibly-change-group group server)
245   (let ((e (assq article nnrss-group-data))
246         (nntp-server-buffer (or buffer nntp-server-buffer))
247         post err)
248     (when e
249       (catch 'error
250         (with-current-buffer nntp-server-buffer
251           (erase-buffer)
252           (goto-char (point-min))
253           (if group
254               (insert "Newsgroups: " group "\n"))
255           (if (nth 3 e)
256               (insert "Subject: " (nnrss-format-string (nth 3 e)) "\n"))
257           (if (nth 4 e)
258               (insert "From: " (nnrss-format-string (nth 4 e)) "\n"))
259           (if (nth 5 e)
260               (insert "Date: " (nnrss-format-string (nth 5 e)) "\n"))
261           (insert "Message-ID: " (format "<%d@%s.nnrss>" (car e) group) "\n")
262           (insert "\n")
263           (if (nth 6 e)
264               (let ((point (point)))
265                 (insert (nnrss-string-as-multibyte (nth 6 e)))
266                 (goto-char point)
267                 (while (search-forward "\n" nil t)
268                   (delete-char -1))
269                 (goto-char (point-max))
270                 (insert "\n\n")
271                 (fill-region point (point))))
272           (if (nth 2 e)
273               (insert (nth 2 e) "\n")))))
274     (cond
275      (err
276       (nnheader-report 'nnrss err))
277      ((not e)
278       (nnheader-report 'nnrss "No such id: %d" article))
279      (t
280       (nnheader-report 'nnrss "Article %s retrieved" (car e))
281       ;; We return the article number.
282       (cons nnrss-group (car e))))))
283
284 (deffoo nnrss-request-list (&optional server)
285   (nnrss-possibly-change-group nil server)
286   (nnrss-generate-active)
287   t)
288
289 (deffoo nnrss-open-server (server &optional defs connectionless)
290   (nnrss-read-server-data server)
291   (nnoo-change-server 'nnrss server defs)
292   t)
293
294 (deffoo nnrss-request-expire-articles
295     (articles group &optional server force)
296   (nnrss-possibly-change-group group server)
297   (let (e days not-expirable changed)
298     (dolist (art articles)
299       (if (and (setq e (assq art nnrss-group-data))
300                (nnmail-expired-article-p
301                 group
302                 (if (listp (setq days (nth 1 e))) days
303                   (days-to-time (- days (time-to-days '(0 0)))))
304                 force))
305           (setq nnrss-group-data (delq e nnrss-group-data)
306                 changed t)
307         (push art not-expirable)))
308     (if changed
309         (nnrss-save-group-data group server))
310     not-expirable))
311
312 (deffoo nnrss-request-delete-group (group &optional force server)
313   (nnrss-possibly-change-group group server)
314   (setq nnrss-server-data
315         (delq (assoc group nnrss-server-data) nnrss-server-data))
316   (nnrss-save-server-data server)
317   (let ((file (expand-file-name
318                (nnrss-translate-file-chars
319                 (concat group (and server
320                                    (not (equal server ""))
321                                    "-")
322                         server ".el")) nnrss-directory)))
323     (ignore-errors
324       (delete-file file)))
325   t)
326
327 (deffoo nnrss-request-list-newsgroups (&optional server)
328   (nnrss-possibly-change-group nil server)
329   (save-excursion
330     (set-buffer nntp-server-buffer)
331     (erase-buffer)
332     (dolist (elem nnrss-group-alist)
333       (if (third elem)
334           (insert (car elem) "\t" (third elem) "\n"))))
335   t)
336
337 (nnoo-define-skeleton nnrss)
338
339 ;;; Internal functions
340
341 (defun nnrss-possibly-change-group (&optional group server)
342   (when (and server
343              (not (nnrss-server-opened server)))
344     (nnrss-open-server server))
345   (when (and group (not (equal group nnrss-group)))
346     (nnrss-read-group-data group server)
347     (setq nnrss-group group)))
348
349 (defvar nnrss-extra-categories '(nnrss-snarf-moreover-categories))
350
351 (defun nnrss-generate-active ()
352   (if (y-or-n-p "Fetch extra categories? ")
353       (dolist (func nnrss-extra-categories)
354         (funcall func)))
355   (save-excursion
356     (set-buffer nntp-server-buffer)
357     (erase-buffer)
358     (dolist (elem nnrss-group-alist)
359       (insert (prin1-to-string (car elem)) " 0 1 y\n"))
360     (dolist (elem nnrss-server-data)
361       (unless (assoc (car elem) nnrss-group-alist)
362         (insert (prin1-to-string (car elem)) " 0 1 y\n")))))
363
364 ;;; Data functions
365
366 (defun nnrss-read-server-data (server)
367   (setq nnrss-server-data nil)
368   (let ((file (expand-file-name
369                (nnrss-translate-file-chars
370                 (concat "nnrss" (and server
371                                      (not (equal server ""))
372                                      "-")
373                         server
374                         ".el"))
375                nnrss-directory)))
376     (when (file-exists-p file)
377       (with-temp-buffer
378         (let ((coding-system-for-read 'binary)
379               emacs-lisp-mode-hook)
380           (insert-file-contents file)
381           (emacs-lisp-mode)
382           (goto-char (point-min))
383           (eval-buffer))))))
384
385 (defun nnrss-save-server-data (server)
386   (gnus-make-directory nnrss-directory)
387   (let ((file (expand-file-name
388                (nnrss-translate-file-chars
389                 (concat "nnrss" (and server
390                                      (not (equal server ""))
391                                      "-")
392                         server ".el"))
393                nnrss-directory)))
394     (let ((coding-system-for-write 'binary)
395           print-level print-length)
396       (with-temp-file file
397         (insert "(setq nnrss-server-data '"
398                 (prin1-to-string nnrss-server-data)
399                 ")\n")))))
400
401 (defun nnrss-read-group-data (group server)
402   (setq nnrss-group-data nil)
403   (setq nnrss-group-hashtb (gnus-make-hashtable))
404   (let ((pair (assoc group nnrss-server-data)))
405     (setq nnrss-group-max (or (cadr pair) 0))
406     (setq nnrss-group-min (+ nnrss-group-max 1)))
407   (let ((file (expand-file-name
408                (nnrss-translate-file-chars
409                 (concat group (and server
410                                    (not (equal server ""))
411                                    "-")
412                         server ".el"))
413                nnrss-directory)))
414     (when (file-exists-p file)
415       (with-temp-buffer
416         (let ((coding-system-for-read 'binary)
417               emacs-lisp-mode-hook)
418           (insert-file-contents file)
419           (emacs-lisp-mode)
420           (goto-char (point-min))
421           (eval-buffer)))
422       (dolist (e nnrss-group-data)
423         (gnus-sethash (nth 2 e) e nnrss-group-hashtb)
424         (if (and (car e) (> nnrss-group-min (car e)))
425             (setq nnrss-group-min (car e)))
426         (if (and (car e) (< nnrss-group-max (car e)))
427             (setq nnrss-group-max (car e)))))))
428
429 (defun nnrss-save-group-data (group server)
430   (gnus-make-directory nnrss-directory)
431   (let ((file (expand-file-name
432                (nnrss-translate-file-chars
433                 (concat group (and server
434                                    (not (equal server ""))
435                                    "-")
436                         server ".el"))
437                nnrss-directory)))
438     (let ((coding-system-for-write 'binary)
439           print-level print-length)
440       (with-temp-file file
441         (insert "(setq nnrss-group-data '"
442                 (prin1-to-string nnrss-group-data)
443                 ")\n")))))
444
445 ;;; URL interface
446
447 (defun nnrss-no-cache (url)
448   "")
449
450 ;; TODO:: disable cache.
451 ;;
452 ;; (defun nnrss-insert-w3 (url)
453 ;;   (require 'url)
454 ;;   (require 'url-cache)
455 ;;   (let ((url-cache-creation-function 'nnrss-no-cache))
456 ;;     (mm-with-unibyte-current-buffer
457 ;;       (nnweb-insert url))))
458
459 (defun nnrss-insert-w3 (url)
460   (mm-with-unibyte-current-buffer
461     (nnweb-insert url)))
462
463 (defun nnrss-decode-entities-unibyte-string (string)
464   (mm-with-unibyte-buffer
465     (insert string)
466     (nnweb-decode-entities)
467     (buffer-substring (point-min) (point-max))))
468
469 (defalias 'nnrss-insert 'nnrss-insert-w3)
470
471 (if (featurep 'xemacs)
472     (defalias 'nnrss-string-as-multibyte 'identity)
473   (defalias 'nnrss-string-as-multibyte 'string-as-multibyte))
474
475 ;;; Snarf functions
476
477 (defun nnrss-check-group (group server)
478   (let ((w3-html-entities (cons '(nbsp . 32) w3-html-entities))
479         file xml subject url extra changed author date)
480     (condition-case err
481         (mm-with-unibyte-buffer
482           (if (and nnrss-use-local
483                    (file-exists-p (setq file (expand-file-name
484                                               (nnrss-translate-file-chars
485                                                (concat group ".xml"))
486                                               nnrss-directory))))
487               (insert-file-contents file)
488             (setq url (or (nth 2 (assoc group nnrss-server-data))
489                           (second (assoc group nnrss-group-alist))))
490             (unless url
491               (setq url
492                     (read-string (format "RSS url of %s: " group "http://")))
493               (let ((pair (assoc group nnrss-server-data)))
494                 (if pair
495                     (setcdr (cdr pair) (list url))
496                   (push (list group nnrss-group-max url) nnrss-server-data)))
497               (setq changed t))
498             (nnrss-insert url))
499           (goto-char (point-min))
500           (while (re-search-forward "\r\n?" nil t)
501             (replace-match "\n"))
502           (goto-char (point-min))
503           (if (re-search-forward "<rdf\\|<rss" nil t)
504               (goto-char (match-beginning 0)))
505           (setq xml (xml-parse-region (point) (point-max))))
506       (error
507        (nnheader-message 1 "Error in group %s: %s" group (cadr err))))
508     (while (and xml (not (assq 'item xml)))
509       (unless (listp (car (setq xml (cddar xml))))
510         (setq xml nil)))
511     (dolist (item (nreverse xml))
512       (when (and (listp item)
513                  (eq 'item (car item))
514                  (setq url (nnrss-node-text (assq 'link (cddr item))))
515                  (setq url (nnrss-decode-entities-unibyte-string url))
516                  (not (gnus-gethash url nnrss-group-hashtb)))
517         (setq subject (nnrss-node-text (assq 'title (cddr item))))
518         (setq extra (or (nnrss-node-text (assq 'description (cddr item)))
519                         (nnrss-node-text (assq 'dc:description (cddr item)))))
520         (setq author (nnrss-node-text (assq 'dc:creator (cddr item))))
521         (setq date (or (nnrss-node-text (assq 'dc:date (cddr item)))
522                        (message-make-date)))
523         (push
524          (list
525           (incf nnrss-group-max)
526           (current-time)
527           url
528           (and subject (nnrss-decode-entities-unibyte-string subject))
529           (and author (nnrss-decode-entities-unibyte-string author))
530           date
531           (and extra (nnrss-decode-entities-unibyte-string extra)))
532          nnrss-group-data)
533         (gnus-sethash url (car nnrss-group-data) nnrss-group-hashtb)
534         (setq changed t)))
535     (when changed
536       (nnrss-save-group-data group server)
537       (let ((pair (assoc group nnrss-server-data)))
538         (if pair
539             (setcar (cdr pair) nnrss-group-max)
540           (push (list group nnrss-group-max) nnrss-server-data)))
541       (nnrss-save-server-data server))))
542
543 (defun nnrss-generate-download-script ()
544   "Generate a download script in the current buffer.
545 It is useful when `(setq nnrss-use-local t)'."
546   (interactive)
547   (insert "#!/bin/sh\n")
548   (insert "WGET=wget\n")
549   (insert "RSSDIR='" (expand-file-name nnrss-directory) "'\n")
550   (dolist (elem nnrss-server-data)
551     (let ((url (or (nth 2 elem)
552                    (second (assoc (car elem) nnrss-group-alist)))))
553       (insert "$WGET -q -O \"$RSSDIR\"/'"
554               (nnrss-translate-file-chars (concat (car elem) ".xml"))
555               "' '" url "'\n"))))
556
557 (defun nnrss-translate-file-chars (name)
558   (let ((nnheader-file-name-translation-alist
559          (append nnheader-file-name-translation-alist '((?' . ?_)))))
560     (nnheader-translate-file-chars name)))
561
562 (defvar nnrss-moreover-url
563   "http://w.moreover.com/categories/category_list_rss.html"
564   "The url of moreover.com categories.")
565
566 (defun nnrss-snarf-moreover-categories ()
567   "Snarf RSS links from moreover.com."
568   (interactive)
569   (let (category name url changed)
570     (with-temp-buffer
571       (nnrss-insert nnrss-moreover-url)
572       (goto-char (point-min))
573       (while (re-search-forward
574               "<A NAME=\"\\([^\"]+\\)\">\\|<A HREF=\"\\(http://[^\"]*moreover\\.com[^\"]+page\\?c=\\([^\"&]+\\)&o=rss\\)" nil t)
575         (if (match-string 1)
576             (setq category (match-string 1))
577           (setq url (match-string 2)
578                 name (nnweb-decode-entities-string
579                       (rfc2231-decode-encoded-string
580                        (match-string 3))))
581           (if category
582               (setq name (concat category "." name)))
583           (unless (assoc name nnrss-server-data)
584             (setq changed t)
585             (push (list name 0 url) nnrss-server-data)))))
586     (if changed
587         (nnrss-save-server-data ""))))
588
589 (defun nnrss-format-string (string)
590   (nnweb-replace-in-string (nnrss-string-as-multibyte string) " *\n *" " "))
591
592 (defun nnrss-node-text (node)
593   (if (and node (listp node))
594       (mapconcat 'nnrss-node-text (cddr node) "")
595     node))
596
597 (provide 'nnrss)
598
599 ;;; nnrss.el ends here