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

Re: w3m-weather



こんにちは、是枝です。

At Fri, 12 Oct 2001 12:08:40 +0900,
> とりあえず、「今日明日の天気」と「今週の天気」のみを表示するようにして
> みました。個人的には、「警報注意報」「生活指数」「ピンポイント天気情報」
> を同じページに追加表示できるようにしたいなあ、と思っています。
「警報注意報」「生活指数」だけやってみました。

「警報注意報」「生活指数」の読み込みあたりは、適切な関数が分からなかっ
たので、いい加減です。

# ごちゃごちゃしている、という気もしてきた...
Index: w3m-weather.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-weather.el,v
retrieving revision 1.14
diff -u -r1.14 w3m-weather.el
--- w3m-weather.el	2001/10/15 01:06:37	1.14
+++ w3m-weather.el	2001/10/26 08:59:58
@@ -333,6 +333,8 @@
 (defcustom w3m-weather-filter-functions
   '(w3m-weather-remove-headers
     w3m-weather-remove-footers
+    w3m-weather-insert-seikatu-sisu 
+    w3m-weather-insert-keihou
     w3m-weather-insert-title)
   "Filter functions to remove useless tags."
   :group 'w3m
@@ -454,6 +456,71 @@
   (goto-char (point-max))
   (insert "</body>"))
 
+(defun w3m-weather-get-seikatu-sisu (url &rest args)
+  (with-temp-buffer
+    (let ((w3m-work-buffer-name (buffer-name)))
+      (w3m-retrieve url)
+      (w3m-with-work-buffer
+	(w3m-decode-buffer url)
+	(goto-char (point-min))
+	(let ((sisu (list '() '()))
+	      name-sisu)
+	  (when (search-forward "<td>指 数</td>" nil t)
+	    (while (re-search-forward "<td nowrap bgcolor=\"#CCCCFF\"> *\\([^ \n]+\\) *</td>" nil t)
+	      (setq name-sisu (match-string 1))
+	      (dotimes (i 2)
+		(forward-line 1)
+		(when (looking-at "<td bgcolor=\"#EEEEEE\">\\([^\n]+\\)</td>")
+		  (push (list name-sisu (match-string 1)) (nth i sisu))))))
+	  (nreverse sisu))))))
+
+(defun w3m-weather-insert-seikatu-sisu (&rest args)
+  (goto-char (point-max))
+  (when (re-search-backward "<a href=\"\\(http://weather.yahoo.co.jp/weather/jp/[^>]+\\)\">生活指数</a>" nil t)
+    (let* ((url (match-string 1))
+	  (sisu-list (w3m-weather-get-seikatu-sisu url))
+	  (case-fold-search t)
+	  sisu-name)
+      (goto-char (point-max))
+      (dolist (seikatu-sisu sisu-list)
+	(when (search-backward "\
+<TR align=middle bgColor=#dcdcdc>
+<TD align=left bgColor=#eeeeee noWrap>
+<FONT size=-1>降水確率(%)</FONT></TD>" nil t)
+	  (goto-char (match-beginning 0))
+	  (dolist (sisu (reverse seikatu-sisu))
+	    (insert "<tr align=middle>\n"
+		    (format "<td align=left nowrap>%s</td>\n" (car sisu))
+		    (format "<td align=center colspan=\"4\" nowrap>%s</td>\n" 
+			    (cadr sisu))
+		    "</tr>\n"))))
+      (when (re-search-forward 
+	     (format "<TR><TD>・<B><a href=\"%s\">生活指数</a></B><FONT size=-1>- 洗濯指数・紫外線指数・肌荒れ指数・布団干し指数</FONT>\n</TD></TR>" url) nil t)
+      (replace-match "")))))
+
+(defun w3m-weather-insert-keihou (&rest args)
+  (let ((case-fold-search t)
+	keihou url)
+    (goto-char (point-min))
+    (when (re-search-forward "<TR><TD>・<B><a href=\"\\(http://weather.yahoo.co.jp/weather/jp/[^>]+\\)\">警報注意報</a></B>" nil t)
+      (setq url (match-string 1))
+      (replace-match "")
+      (with-temp-buffer
+	(let ((w3m-work-buffer-name (buffer-name)))
+	  (w3m-retrieve url)
+	  (w3m-with-work-buffer
+	    (w3m-decode-buffer url)
+	    (goto-char (point-min))
+	    (when (search-forward 
+		   "<tr valign=\"top\">\n<td colspan=\"3\" width=\"4\">\n</td>\n</tr>" nil t)
+	      (delete-region (point-min) (match-end 0))
+	      (when (search-forward "</table>" nil t)
+		(delete-region (point-max) (match-end 0))
+		(goto-char (point-min))
+		(insert "<br><table width=\"100%\">\n")
+		(setq keihou (buffer-substring (point-min) (point-max))))))))
+	(forward-line 1)
+	(insert keihou))))
 
 (provide 'w3m-weather)
 ;;; w3m-weather.el ends here.
-- 
是枝 和義