[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: sb-emacswiki.el / sb-heise.el / sb-spigel.el



Quote [ TSUCHIYA Masatoshi * 3901. September 1993 ]

> I have imported sb-emacswiki.el, sb-heise.el and sb-spigel.el to our
> CVS repository, and slightly modified their comments to keep
> consistency through other shimbun modules.
> Could you check them, David?

I've also create a shimbun modul for the emacswiki and spiegel.
This moduls doesn't use RSS. I think that's better.
See <87zn8m4t7g.fsf@news.gentoo.b-j-t.de> for sb-emacswiki.el.
sb-spiegel.el does not work yet. :-/
Here are the errors:
,----[ Gnus ]
| Connecting to spiegel...
| Opening nnshimbun server on spiegel...
| Denied server
| Opening nnshimbun server on spiegel...failed
`----
,----[ Wanderlust ]
| byte-code: Wrong type argument: stringp, nil
`----

The Code:
;;; sb-spiegel.el --- w3m shimbun for spiegel online

;; Copyright (C) 2004 Markus Knittig

;; Author: Markus Knittig <markus.knittig@arcor.de>
;; Version: 0.1
;; Keywords: emacs-w3m, shimbun, hypermedia

;; This file is not part of GNU Emacs.

;; This 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 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 GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;;; Code:

(require 'shimbun)

(luna-define-class shimbun-spiegel (shimbun) ())

(defvar shimbun-spiegel-url "http://www.spiegel.de";)

(defvar shimbun-spiegel-group-path-alist
  '(("schlagzeilen" . "/schlagzeilen/")))

(defvar shimbun-spiegel-x-face-alist
  '(("default" . "X-Face: $(Bq\"x1-o^p_dk2@)6}r^o%([c7^4*T'wiP,:GPLsIkgFTzuBTk1*O!8p8\\tbagrg`K~_Xp\
aEJr$2yu$=TJ.G=(oF1!,z$9\"M$Y~_%4&,*~xR@Rj%,zU~4:Nykk4]q/n6lL:'8Qe+i4g7l[$R)/Bh\
'+]8?ovZvK5?0Z<9L0i^~EVD~U7Wh~9y>P0>-x0#e)%lcD\"gg][f%vpAb}0mdo|TDF.W7MZCcAmAM)\
r62lDvF/1oFfSpK;vH';`]hX`@b:!7Gyz=}O#]iUa1")))

(defvar shimbun-spiegel-htmlentities-alist
  '(("&Auml;" . "A")
    ("&auml;" . "ä")
    ("&Ouml;" . "Ö")
    ("&ouml;" . "ö")
    ("&Uuml;" . "Ü")
    ("&uuml;" . "ü")
    ("&szlig;" . "ß")
    ("&euro;" . "¤")
    ("&amp;" . "&")
    ("&laquo;" . "«")
    ("&raquo;" . "»")
    ("&quote;" . "\"")))

(defvar shimbun-spiegel-htmlentities
  (let ((hash (make-hash-table :test 'equal)))
    (dolist (pair shimbun-spiegel-htmlentities-alist)
      (puthash (car pair) (cdr pair) hash))
    hash))

(defconst shimbun-spiegel-htmlentities-regexp
  (regexp-opt (mapcar 'car
		      (append shimbun-spiegel-htmlentities-alist))))

(defvar shimbun-spiegel-groups
  (mapcar 'car shimbun-spiegel-group-path-alist))

(luna-define-method shimbun-index-url ((shimbun shimbun-spiegel))
  (concat shimbun-spiegel-url
     	  (cdr (assoc (shimbun-current-group-internal shimbun)
     		      shimbun-spiegel-group-path-alist))))

(defun shimbun-spiegel-get-headers ()
  (let ((regexp "<a href=\"\\(.+?\\)\">\\(.+?\\)</a> <nobr><font.+?>(\\(.+?\\), \\(.+?\\))</font>")
	(regexp-day "<p><b><font size=\"-2\" class=\"gesperrt\">.+?<hr noshade size=\"1\"></font></b>")
	(regexp-date "\\([0-9]\\{2\\}\\)\. \\([A-za-z]+\\)     \\([0-9]\\{4\\}\\), \\([0-9]\\{2\\}:[0-9]\\{2\\}\\)")
	date subject from id url headers day month year time)
    (catch 'stop
      (setq from "Spiegel Online <invalid@spiegel.de>")
      ;;find the day
      (while (re-search-forward regexp-day nil t nil)
	;;find the entry
	(while (re-search-forward regexp nil t nil)
	  (setq url (w3m-expand-url (match-string 1) shimbun-spiegel-url))
	  (setq subject (concat "[" (match-string 3) "] " (match-string 2)))
	  (setq date (match-string 4))
	  ;;strip html tags in subject
	  (while (string-match "<.+?>" subject)
	    (setq subject (replace-match "" nil t subject)))
	  ;;replace html entities in subject
	  (while (string-match shimbun-spiegel-htmlentities-regexp subject)
	    (setq subject (replace-match
			   (gethash (match-string 0 subject) shimbun-spiegel-htmlentities) t t subject)))
	  ;;parse date
	  (when (string-match regexp-date date)
	    (setq day (match-string 1 date))
	    (setq month (match-string 2 date))
	    (setq year (match-string 3 date))
	    (setq time (match-string 4 date))
	    (setq date (shimbun-make-date-string
			(string-to-number year)  ; year
			(cond                    ; month
			 ((string-match month "Januar")  (string-to-number "1"))
			 ((string-match month "Februar") (string-to-number "2"))
			 ((string-match month "M.+?rz") (string-to-number "3"))
			 ((string-match month "April") (string-to-number "4"))
			 ((string-match month "Mai") (string-to-number "5"))
			 ((string-match month "Juni") (string-to-number "6"))
			 ((string-match month "Juli") (string-to-number "7"))
			 ((string-match month "August") (string-to-number "8"))
			 ((string-match month "September") (string-to-number "9"))
			 ((string-match month "Oktober") (string-to-number "10"))
			 ((string-match month "November") (string-to-number "11"))
			 ((string-match month "Dezember") (string-to-number "12")))
			(string-to-number day)   ; day
			time                     ; time
	    "+0200")))                           ; timezone
	  ;;create an id
	  (setq id (concat "<" date "." subject "@spiegel.de>" ))
	  (when (shimbun-search-id shimbun id)
	    (throw 'stop nil))
	  (push (shimbun-make-header
		 0 (shimbun-mime-encode-string subject)
		 (shimbun-mime-encode-string from)
		 date id "" 0 0 url)
		headers))))
    headers))

(luna-define-method shimbun-get-headers ((shimbun shimbun-spiegel) &optional range)
  (shimbun-spiegel-get-headers))

(defun shimbun-spiegel-wash-article (header)
  (save-excursion
    ;;strip unwanted stuff
    (let ((regexp-article-begin "OAS_RICH('Frame1');")
          (regexp-article-end "OAS_RICH('x32');")
          begin-region end-region)
      (when (re-search-forward regexp-article-begin nil t nil)
	(forward-line 7)
	(setq end-region (point))
	(setq begin-region (point-min))
	(delete-region begin-region end-region))
      (when (re-search-forward regexp-article-end nil t nil)
	(forward-line -3)
	(setq begin-region (point))
	(setq end-region (point-max))
	(delete-region begin-region end-region)))
    
    ;;strip ads
    (goto-char (point-min))
    (let ((regexp-ads-begin "<script language=.+?>")
          (regexp-ads-end "</noscript> <br clear=.+?/>")
          begin-region end-region)
      (when (re-search-forward regexp-ads-begin nil t nil)
	(beginning-of-line)
	(setq begin-region (point))
	(when (re-search-forward regexp-ads-end nil t nil)
	  (end-of-line)
	  (setq end-region (point))
	  (delete-region begin-region end-region))))

    ;;fix images
    (goto-char (point-min))
    (let ((regexp-img "<img src=\"\\(.+?\\)\""))
      (while (re-search-forward regexp-img nil t nil)
	(replace-match (concat "<img src=\"" shimbun-spiegel-url "\\1\""))))

    ;;fix links
    (goto-char (point-min))
    (let ((regexp-links "<a href=\"\\(.+?\\)\""))
      (while (re-search-forward regexp-links nil t nil)
	(replace-match (concat "<a href=\"" shimbun-spiegel-url "\\1\""))))
    
    ;;remove \r
    (goto-char (point-min))
    (while (re-search-forward "\r" nil t nil)
      (replace-match ""))))

;; (luna-define-method shimbun-make-contents ((shimbun shimbun) header)
;; 		    (shimbun-make-html-contents shimbun header))

;; (luna-define-method shimbun-make-contents
;;  		    :before ((shimbun shimbun-heise) header)
;;  		    (shimbun-spiegel-wash-article header)
;; 		    ;;  (shimbun-make-html-contents shimbun header))
;;  		    (shimbun-header-insert-and-buffer-string shimbun header "iso-8859-1" t))

(luna-define-method shimbun-make-contents ((shimbun shimbun-emacswiki) header)
		    (shimbun-header-insert-and-buffer-string shimbun header nil t))

(provide 'sb-spiegel)
;;; sb-spiegel.el ends here.

Any suggestions?

Best regards,
 Markus