;; * mixi-get-new-comments
;; * mixi-get-messages
;; * mixi-get-introductions
+;; * mixi-get-news
;;
;; API for posting:
;;
(defconst mixi-diary-list-regexp
"<tr VALIGN=top>
<td ALIGN=center ROWSPAN=3 NOWRAP bgcolor=#F2DDB7><font COLOR=#996600>\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</font>\\(<br><input type=\"checkbox\" name=\"diary_id\" value=\"[0-9]+\">\\|\\)</td>
-<td bgcolor=\"#FFF4E0\"> <a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">\\(.*\\)</a></td>
-</tr>
-<tr>
-<td ALIGN=center BGCOLOR=#FFFFFF>
-<table BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH=410>
-<tr>
-<td CLASS=h120>
-
-\\(.*\\)
-
-?<br>
-
-</td></tr>
-</table>
-</td></tr>")
+<td bgcolor=\"#FFF4E0\"> <a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">\\(.*\\)</a></td>")
(defun mixi-get-diaries (&rest friend-or-range)
"Get diaries of FRIEND."
(string-to-number (nth 2 item))
(string-to-number (nth 1 item))
month year)
- (nth 6 item) (nth 7 item))))
+ (nth 6 item))))
items))))
(defmacro mixi-new-diary-list-page ()
(defconst mixi-bbs-list '(mixi-topic mixi-event))
(defmacro mixi-bbs-p (object)
- `(when (memq (mixi-object-class ,object) mixi-bbs-list)
- t))
+ `(memq (mixi-object-class ,object) mixi-bbs-list))
(defun mixi-bbs-community (object)
"Return the community of OBJECT."
(defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
(defmacro mixi-message-box-p (box)
- `(when (memq ,box mixi-message-box-list)
- t))
+ `(memq ,box mixi-message-box-list))
(defun mixi-message-box-name (box)
"Return the name of BOX."
;; News object.
(defvar mixi-news-cache (make-hash-table :test 'equal))
-(defun mixi-make-news (media-id id &optional time title content)
+(defun mixi-make-news (media-id id &optional media time title content)
"Return a news object."
(mixi-make-cache (list media-id id)
- (cons 'mixi-news (vector nil media-id id time title
+ (cons 'mixi-news (vector nil media-id id media time title
content))
mixi-news-cache))
(defconst mixi-news-title-regexp
"<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)</td>")
-(defconst mixi-news-time-regexp
- "<td COLSPAN=\"2\" ALIGN=\"right\">(.+ - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")
+(defconst mixi-news-media-time-regexp
+ "<td COLSPAN=\"2\" ALIGN=\"right\">(\\(.+\\) - \\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")
(defconst mixi-news-content-regexp
"<td CLASS=\"h150\">
(if (string-match mixi-news-title-regexp buffer)
(mixi-news-set-title news (match-string 1 buffer))
(mixi-realization-error 'cannot-find-title news))
- (if (string-match mixi-news-time-regexp buffer)
- (let ((year (nth 5 (decode-time (current-time))))
- (month (nth 4 (decode-time (current-time))))
- (month-of-item (string-to-number (match-string 1 buffer))))
- (when (> month-of-item month)
- (decf year))
- (mixi-news-set-time
- news (encode-time 0 (string-to-number (match-string 4 buffer))
- (string-to-number (match-string 3 buffer))
- (string-to-number (match-string 2 buffer))
- month year)))
- (mixi-realization-error 'cannot-find-time news))
+ (if (string-match mixi-news-media-time-regexp buffer)
+ (progn
+ (mixi-news-set-media news (match-string 1 buffer))
+ (let ((year (nth 5 (decode-time (current-time))))
+ (month (nth 4 (decode-time (current-time))))
+ (month-of-item (string-to-number (match-string 2 buffer))))
+ (when (> month-of-item month)
+ (decf year))
+ (mixi-news-set-time
+ news (encode-time 0 (string-to-number (match-string 5 buffer))
+ (string-to-number (match-string 4 buffer))
+ (string-to-number (match-string 3 buffer))
+ month year))))
+ (mixi-realization-error 'cannot-find-media-time news))
(if (string-match mixi-news-content-regexp buffer)
(mixi-news-set-content news (match-string 1 buffer))
(mixi-realization-error 'cannot-find-content news)))
(signal 'wrong-type-argument (list 'mixi-news-p news)))
(aref (cdr news) 2))
-(defun mixi-news-time (news)
- "Return the time of NEWS."
+(defun mixi-news-media (news)
+ "Return the media of NEWS."
(unless (mixi-news-p news)
(signal 'wrong-type-argument (list 'mixi-news-p news)))
(unless (aref (cdr news) 3)
(mixi-realize-news news))
(aref (cdr news) 3))
-(defun mixi-news-title (news)
- "Return the title of NEWS."
+(defun mixi-news-time (news)
+ "Return the time of NEWS."
(unless (mixi-news-p news)
(signal 'wrong-type-argument (list 'mixi-news-p news)))
(unless (aref (cdr news) 4)
(mixi-realize-news news))
(aref (cdr news) 4))
+(defun mixi-news-title (news)
+ "Return the title of NEWS."
+ (unless (mixi-news-p news)
+ (signal 'wrong-type-argument (list 'mixi-news-p news)))
+ (unless (aref (cdr news) 5)
+ (mixi-realize-news news))
+ (aref (cdr news) 5))
+
(defun mixi-news-content (news)
"Return the content of NEWS."
(unless (mixi-news-p news)
(signal 'wrong-type-argument (list 'mixi-news-p news)))
(mixi-realize-news news)
- (aref (cdr news) 5))
+ (aref (cdr news) 6))
+
+(defun mixi-news-set-media (news media)
+ "Set the media of NEWS."
+ (unless (mixi-news-p news)
+ (signal 'wrong-type-argument (list 'mixi-news-p news)))
+ (aset (cdr news) 3 media))
(defun mixi-news-set-time (news time)
"Set the time of NEWS."
(unless (mixi-news-p news)
(signal 'wrong-type-argument (list 'mixi-news-p news)))
- (aset (cdr news) 3 time))
+ (aset (cdr news) 4 time))
(defun mixi-news-set-title (news title)
"Set the title of NEWS."
(unless (mixi-news-p news)
(signal 'wrong-type-argument (list 'mixi-news-p news)))
- (aset (cdr news) 4 title))
+ (aset (cdr news) 5 title))
(defun mixi-news-set-content (news content)
"Set the content of NEWS."
(unless (mixi-news-p news)
(signal 'wrong-type-argument (list 'mixi-news-p news)))
- (aset (cdr news) 5 content))
+ (aset (cdr news) 6 content))
(defconst mixi-news-category-list '(domestic politics economy area abroad
sports entertainment IT))
(defmacro mixi-news-category-p (category)
- `(when (memq ,category mixi-news-category-list)
- t))
+ `(memq ,category mixi-news-category-list))
(defun mixi-news-category-id (category)
"Return the id of CATEGORY."
(1+ (- (length mixi-news-category-list)
(length (memq category mixi-news-category-list))))))
-(defmacro mixi-news-list-page (category)
- `(concat "http://news.mixi.jp/list_news_category.pl?page=%d&sort=1"
- (concat "&id=" (mixi-news-category-id category) "&type=bn")))
+(defconst mixi-news-sort-list '(newest pickup))
+
+(defmacro mixi-news-sort-p (sort)
+ `(memq ,sort mixi-news-sort-list))
+
+(defun mixi-news-sort-id (sort)
+ "Return the id of SORT."
+ (unless (mixi-news-sort-p sort)
+ (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
+ (number-to-string
+ (- (length mixi-news-sort-list)
+ (length (memq sort mixi-news-sort-list)))))
+
+(defmacro mixi-news-list-page (category sort)
+ `(concat "http://news.mixi.jp/list_news_category.pl?page=%d"
+ "&sort=" (mixi-news-sort-id ,sort)
+ "&id=" (mixi-news-category-id ,category)
+ "&type=bn"))
(defconst mixi-news-list-regexp
"<tr bgcolor=\"\\(#FCF5EB\\|#FFFFFF\\)\">
\\(<IMG SRC=\"http://img\\.mixi\\.jp/img/news_camera3\\.gif\" WIDTH=\"11\" HEIGHT=\"12\">\\|\\)
</td>
-<td WIDTH=\"1%\" nowrap CLASS=\"f08\"><A HREF=\"list_news_media\\.pl\\?id=[0-9]+\">.+</A></td>
+<td WIDTH=\"1%\" nowrap CLASS=\"f08\"><A HREF=\"list_news_media\\.pl\\?id=[0-9]+\">\\(.+\\)</A></td>
<td WIDTH=\"1%\" nowrap CLASS=\"f08\">\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\)</td></tr>")
-(defun mixi-get-news (category &optional range)
- "Get news of CATEGORY."
+(defun mixi-get-news (category sort &optional range)
+ "Get news of CATEGORY and SORT."
(unless (mixi-news-category-p category)
(signal 'wrong-type-argument (list 'mixi-news-category-p category)))
- (let ((items (mixi-get-matched-items (mixi-news-list-page category)
- mixi-news-list-regexp
- range))
- (year (nth 5 (decode-time (current-time))))
- (month (nth 4 (decode-time (current-time)))))
- (mapcar (lambda (item)
- (let ((month-of-item (string-to-number (nth 5 item))))
- (when (> month-of-item month)
- (decf year))
- (setq month month-of-item)
- (mixi-make-news (nth 2 item) (nth 1 item)
- (encode-time
- 0 (string-to-number (nth 8 item))
- (string-to-number (nth 7 item))
- (string-to-number (nth 6 item))
- month year)
- (nth 3 item))))
- items)))
+ (unless (mixi-news-sort-p sort)
+ (signal 'wrong-type-argument (list 'mixi-news-sort-p sort)))
+ (let ((items (mixi-get-matched-items (mixi-news-list-page category sort)
+ mixi-news-list-regexp
+ range))
+ (year (nth 5 (decode-time (current-time))))
+ (month (nth 4 (decode-time (current-time)))))
+ (mapcar (lambda (item)
+ (let ((month-of-item (string-to-number (nth 6 item))))
+ (when (> month-of-item month)
+ (decf year))
+ (setq month month-of-item)
+ (mixi-make-news (nth 2 item) (nth 1 item) (nth 5 item)
+ (encode-time
+ 0 (string-to-number (nth 9 item))
+ (string-to-number (nth 8 item))
+ (string-to-number (nth 7 item))
+ month year)
+ (nth 3 item))))
+ items)))
(provide 'mixi)