;;; sb-yomiuri.el --- shimbun backend for www.yomiuri.co.jp -*- coding: iso-2022-7bit; -*- ;; Author: TSUCHIYA Masatoshi , ;; Yuuichi Teranishi , ;; Katsumi Yamaoka ;; Keywords: news ;;; Copyright: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, you can either send email to this ;; program's maintainer or write to: The Free Software Foundation, ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Original code was nnshimbun.el written by ;; TSUCHIYA Masatoshi . ;;; Code: (require 'shimbun) (require 'sb-text) (luna-define-class shimbun-yomiuri (shimbun-japanese-newspaper shimbun-text) ()) (defvar shimbun-yomiuri-top-level-domain "yomiuri.co.jp" "Name of the top level domain for the Yomiuri On-line.") (defvar shimbun-yomiuri-url (concat "http://www." shimbun-yomiuri-top-level-domain "/") "Name of the parent url.") (defvar shimbun-yomiuri-group-table (let* ((s0 "[\t\n ]*") (s1 "[\t\n ]+") (no-nl "[^\n<>]+") (default (list (concat "" s0 ;; 4. subject "\\(" no-nl "\\)" s0 "(" ;; 5. month "\\([01]?[0-9]\\)" "/" ;; 6. day "\\([0-3]?[0-9]\\)" s1 ;; 7. hour:minute "\\([012][0-9]:[0-5][0-9]\\)" ")" s0 "") 1 2 3 4 5 6 7))) `(("business" "経済" "index.htm" ,@default) ("culture" "芸能・文化" "index.htm" ,@default) ("editorial" "社説・コラム" "index.htm" ,(concat "" s0 ;; 4. month(ja) "\\([01]?[0-9]\\)" "月" ;; 5. day(ja) "\\([0-3]?[0-9]\\)" "日付・" ;; 6. subject "\\(" no-nl "\\)" s0 "") 1 2 3 6 4 5) ("kyoiku" "教育メール" "index.htm" ,(concat "]+>" s0 ;; 5. subject "\\([^<]+\\)" "\\(" s0 "<[^>]+>\\)+" s0 ;; 7. month "\\([01]?[0-9]\\)" "月\\(" s0 "<[^>]+>\\)+" s0 ;; 9 day "\\([0-3]?[0-9]\\)" "日") 1 3 4 5 7 9) ("national" "社会" "index.htm" ,@default) ("obit" "おくやみ" "index.htm" ,(concat "" s0 ;; 4. subject "\\(" no-nl "\\)" s0 "(" ;; 5. month "\\([01]?[0-9]\\)" "/" ;; 6. day "\\([0-3]?[0-9]\\)" ")" s0 "") 1 2 3 4 5 6) ("politics" "政治" "index.htm" ,@default) ("science" "科学" "index.htm" ,@default) ("sports" "スポーツ" "index.htm" ,@default) ("world" "国際" "index.htm" ,@default))) "Alist of group names, their Japanese translations, index pages, regexps and numbers. Regexp may contain the \"%s\" token which is replaced with a regexp-quoted group name. Numbers point to the search result in order of [0]a url, [1,2]serial numbers, [3]a subject, [4]a month, [5]a day, \[6]an hour:minute and [7-]extra keywords.") (defvar shimbun-yomiuri-content-start "\n\n") (defvar shimbun-yomiuri-content-end "\n\n") (defvar shimbun-yomiuri-x-face-alist '(("default" . "X-Face: #sUhc'&(fVr$~y)\ i\"#,TNF|j.dEh2dAzfa4=IH&llI]S<-\"dznMW2_j\n [N1a%n{SU&E&\ Ex;xlc)9`]D07rPEsbgyjP@\"_@g-kw!~TJNilrSC![\t\n ]*\\(<[^<>]+>[\t\n ]*\\)+" ;; 6. subject "\\([^<>]+\\)" "[\t\n ]*<")) (regexp-quote group)) nil t)) (setq month (string-to-number (match-string 3)) day (string-to-number (match-string 4))) (save-match-data (when (re-search-forward (concat "(\\([01]?[0-9]\\)/\\([0-3]?[0-9]\\)[\t\n ]+\ \\([012][0-9]:[0-5][0-9]\\))[\t\n ]+= (- month cmonth) 2) (1- cyear)) ((and (= 1 month) (= 12 cmonth)) (1+ cyear)) (t cyear)) month day time) ;; id (concat "<" (buffer-substring (match-beginning 2) (match-end 4)) "." (buffer-substring (match-end 4) (match-end 2)) "%" group "." shimbun-yomiuri-top-level-domain ">") ;; references, chars, lines "" 0 0 ;; xref (concat shimbun-yomiuri-url (match-string 1))) headers)) (setq regexp (assoc group shimbun-yomiuri-group-table) numbers (nthcdr 4 regexp) regexp (format (nth 3 regexp) (regexp-quote group))) ;; Generating headers. (while (re-search-forward regexp nil t) (if (string-equal group "editorial") (setq month (shimbun-yomiuri-japanese-string-to-number (match-string (nth 4 numbers))) day (shimbun-yomiuri-japanese-string-to-number (match-string (nth 5 numbers)))) (setq month (string-to-number (match-string (nth 4 numbers))) day (string-to-number (match-string (nth 5 numbers))))) (push (shimbun-make-header ;; number 0 ;; subject (if (string-equal "editorial" group) (shimbun-mime-encode-string (format "%02d/%02d %s" month day (shimbun-yomiuri-shorten-brackets-in-string (match-string (nth 3 numbers))))) (shimbun-mime-encode-string (match-string (nth 3 numbers)))) ;; from from ;; date (shimbun-make-date-string (cond ((>= (- month cmonth) 2) (1- cyear)) ((and (= 1 month) (= 12 cmonth)) (1+ cyear)) (t cyear)) month day (when (nth 6 numbers) (match-string (nth 6 numbers)))) ;; id (concat "<" (match-string (nth 1 numbers)) "." (match-string (nth 2 numbers)) "%" group "." shimbun-yomiuri-top-level-domain ">") ;; references, chars, lines "" 0 0 ;; xref (concat shimbun-yomiuri-url (match-string (nth 0 numbers)))) headers)) (shimbun-sort-headers headers))) (luna-define-method shimbun-get-headers ((shimbun shimbun-yomiuri) &optional range) (shimbun-yomiuri-get-headers shimbun)) (defun shimbun-yomiuri-prepare-article (shimbun header) "Prepare an article: adjusting a date header if there is a correct information available, removing useless contents, etc." (let ((group (shimbun-current-group-internal shimbun)) (case-fold-search t) start) (if (string-equal group "kyoiku") (progn (when (or (re-search-forward "\ [\t\n ]*" nil t) (re-search-forward "\ [\t\n ]*" nil t)) (delete-region (point-min) (point))) (when (or (re-search-forward "[\t\n ]*" nil t) (re-search-forward "[\t\n ]*\ [\t\n ]*" nil t) (re-search-forward "[\t\n ]*" nil t)) (delete-region (match-beginning 0) (point-max))) (goto-char (point-min)) (when (re-search-forward "\ \\([\t\n ]*写真の拡大[\t\n ]*\ ]+>[\t\n ]*\\)" nil t) (delete-region (match-beginning 1) (match-end 1)))) (when (and (re-search-forward (shimbun-content-start-internal shimbun) nil t) (setq start (point)) (re-search-forward (shimbun-content-end-internal shimbun) nil t)) (narrow-to-region start (match-beginning 0)) (goto-char (point-max)) (forward-line -1) (when (re-search-forward "\\(20[0-9][0-9]\\)/\\(1?[0-9]\\)/\ \\([123]?[0-9]\\)/\\([012][0-9]:[0-5][0-9]\\)" nil t) (shimbun-header-set-date header (shimbun-make-date-string (string-to-number (match-string 1)) (string-to-number (match-string 2)) (string-to-number (match-string 3)) (match-string 4)))) (goto-char (point-min)) (shimbun-remove-tags "" "") ;; Break continuous lines. (goto-char (point-min)) (when (and (string-equal group "editorial") (string-match " \\(よみうり寸評\\|編集手帳\\)\\'" (shimbun-header-subject header 'no-encode))) (goto-char (point-min)) (while (search-forward "◆" nil t) (replace-match "。
\\&
"))) (widen)))) (goto-char (point-min))) (luna-define-method shimbun-make-contents :before ((shimbun shimbun-yomiuri) header) (shimbun-yomiuri-prepare-article shimbun header)) (provide 'sb-yomiuri) ;;; sb-yomiuri.el ends here