* sb-airs.el (toplevel): Require 'sb-mhonarc.
[elisp/wanderlust.git] / elmo / sb-yomiuri.el
1 ;;; sb-yomiuri.el --- shimbun backend for www.yomiuri.co.jp
2
3 ;; Author: TSUCHIYA Masatoshi <tsuchiya@pine.kuee.kyoto-u.ac.jp>
4 ;;         Akihiro Arisawa    <ari@atesoft.advantest.co.jp>
5 ;;         Yuuichi Teranishi <teranisi@gohome.org>
6
7 ;; Keywords: news
8
9 ;;; Copyright:
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; if not, you can either send email to this
23 ;; program's maintainer or write to: The Free Software Foundation,
24 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Original code was nnshimbun.el written by
29 ;; TSUCHIYA Masatoshi <tsuchiya@pine.kuee.kyoto-u.ac.jp>.
30
31 ;;; Code:
32
33 (require 'shimbun)
34 (require 'sb-text)
35
36 (luna-define-class shimbun-yomiuri (shimbun shimbun-text) ())
37
38 (defvar shimbun-yomiuri-url "http://www.yomiuri.co.jp/")
39 (defvar shimbun-yomiuri-groups '("shakai" "sports" "seiji" "keizai"
40                                  "kokusai" "fuho"))
41 (defvar shimbun-yomiuri-coding-system  (static-if (boundp 'MULE)
42                                            '*sjis* 'shift_jis))
43 (defvar shimbun-yomiuri-from-address  "webmaster@www.yomiuri.co.jp")
44 (defvar shimbun-yomiuri-content-start "\n<!--  honbun start  -->\n")
45 (defvar shimbun-yomiuri-content-end  "\n<!--  honbun end  -->\n")
46
47 (defvar shimbun-yomiuri-group-path-alist
48   '(("shakai" . "04")
49     ("sports" . "06")
50     ("seiji"  . "01")
51     ("keizai" . "02")
52     ("kokusai" . "05")
53     ("fuho"    . "zz")))
54
55 (luna-define-method shimbun-index-url ((shimbun shimbun-yomiuri))
56   (concat (shimbun-url-internal shimbun)
57           (cdr (assoc (shimbun-current-group-internal shimbun)
58                       shimbun-yomiuri-group-path-alist))
59           "/index.htm"))
60
61 (luna-define-method shimbun-get-headers ((shimbun shimbun-yomiuri))
62   (let ((case-fold-search t)
63         start headers)
64     (goto-char (point-min))
65     (when (and (search-forward
66                 (format "\n<!-- /news/list start -->\n"
67                         (shimbun-current-group-internal shimbun)) nil t)
68                (setq start (point))
69                (search-forward
70                 (format "\n<!-- /news/list end -->\n"
71                         (shimbun-current-group-internal shimbun)) nil t))
72       (forward-line -1)
73       (save-restriction
74         (narrow-to-region start (point))
75         (goto-char start)
76         (while (re-search-forward
77                 "<a href=\"/\\([0-9]+\\)/\\(\\(\\([0-9][0-9][0-9][0-9]\\)\\([0-9][0-9]\\)\\([0-9][0-9]\\)[A-z0-9]+\\)\\.htm\\)\"[^>]*>"
78                 nil t)
79           (let ((url   (concat (match-string 1) "/"
80                                (match-string 2)))
81                 (id    (format "<%s%s%%%s>"
82                                (match-string 1)
83                                (match-string 3)
84                                (shimbun-current-group-internal shimbun)))
85                 (year  (string-to-number (match-string 4)))
86                 (month (string-to-number (match-string 5)))
87                 (day   (string-to-number (match-string 6)))
88                 (subject (mapconcat
89                           'identity
90                           (split-string
91                            (buffer-substring
92                             (match-end 0)
93                             (progn (search-forward "<br>" nil t) (point)))
94                            "<[^>]+>")
95                           ""))
96                 date)
97             (when (string-match "^\e$B"!\e(B" subject)
98               (setq subject (substring subject (match-end 0))))
99             (if (string-match "(\\([0-9][0-9]:[0-9][0-9]\\))$" subject)
100                 (setq date (shimbun-make-date-string
101                             year month day (match-string 1 subject))
102                       subject (substring subject 0 (match-beginning 0)))
103               (setq date (shimbun-make-date-string year month day)))
104             (push (shimbun-make-header
105                    0
106                    (shimbun-mime-encode-string subject)
107                    (shimbun-from-address-internal shimbun)
108                    date id "" 0 0 (concat
109                                    (shimbun-url-internal shimbun)
110                                    url))
111                   headers)))))
112     headers))
113
114 (provide 'sb-yomiuri)
115
116 ;;; sb-yomiuri.el ends here