From: bg66 Date: Mon, 27 Nov 2006 13:05:06 +0000 (+0000) Subject: * mixi.el (mixi-event-cache): New variable. X-Git-Tag: mixi-el-1_0_0~188 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=1b2fa51761feb93873b6b25e068e1660475cb909;p=elisp%2Fmixi.git * mixi.el (mixi-event-cache): New variable. (mixi-make-event): New function. (mixi-event-url-regexp): New constant. (mixi-make-event-from-url): New function. (mixi-event-p): New macro. (mixi-event-page): Ditto. (mixi-event-time-regexp): New regexp. (mixi-event-title-regexp): Ditto. (mixi-event-owner-regexp): Ditto. (mixi-event-date-regexp): Ditto. (mixi-event-place-regexp): Ditto. (mixi-event-detail-regexp): Ditto. (mixi-event-limit-regexp): Ditto. (mixi-event-members-regexp): Ditto. (mixi-event-realize): New function. (mixi-event-community): New accessor method. (mixi-event-id): Ditto. (mixi-event-time): Ditto. (mixi-event-title): Ditto. (mixi-event-owner): Ditto. (mixi-event-date): Ditto. (mixi-event-place): Ditto. (mixi-event-detail): Ditto. (mixi-event-limit): Ditto. (mixi-event-members): Ditto. (mixi-event-set-time): Ditto. (mixi-event-set-title): Ditto. (mixi-event-set-owner): Ditto. (mixi-event-set-date): Ditto. (mixi-event-set-place): Ditto. (mixi-event-set-detail): Ditto. (mixi-event-set-limit): Ditto. (mixi-event-set-members): Ditto. (mixi-bbs-list-page): Rename from `mixi-topic-list-page'. (mixi-bbs-list-regexp): Rename from `mixi-topic-list-regexp'. (mixi-get-bbses): Rename from `mixi-get-topics'. (mixi-new-bbs-list-page): Rename from `mixi-new-topic-list-page'. (mixi-new-bbs-list-regexp): Rename from `mixi-new-topic-list-regexp'. (mixi-get-new-bbses): Rename from `mixi-get-new-topics'. (mixi-bbs-list-regexp): Follow the change above. (mixi-get-bbses): Ditto. (mixi-new-bbs-list-regexp): Ditto. (mixi-get-new-bbses): Ditto. (mixi-event-comment-list-page): New function. (mixi-event-comment-list-regexp): New constant. * sb-mixi.el (shimbun-mixi-group-alist): Follow the change above. (shimbun-mixi-make-subject): Ditto. (shimbun-mixi-make-xref): Ditto. (shimbun-mixi-get-headers): Ditto. (shimbun-get-headers): Ditto. (shimbun-mixi-make-body): New function. (shimbun-article): Follow the change above. --- diff --git a/ChangeLog b/ChangeLog index 800fff5..9db03d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,61 @@ 2006-11-27 OHASHI Akira + * mixi.el (mixi-event-cache): New variable. + (mixi-make-event): New function. + (mixi-event-url-regexp): New constant. + (mixi-make-event-from-url): New function. + (mixi-event-p): New macro. + (mixi-event-page): Ditto. + (mixi-event-time-regexp): New regexp. + (mixi-event-title-regexp): Ditto. + (mixi-event-owner-regexp): Ditto. + (mixi-event-date-regexp): Ditto. + (mixi-event-place-regexp): Ditto. + (mixi-event-detail-regexp): Ditto. + (mixi-event-limit-regexp): Ditto. + (mixi-event-members-regexp): Ditto. + (mixi-event-realize): New function. + (mixi-event-community): New accessor method. + (mixi-event-id): Ditto. + (mixi-event-time): Ditto. + (mixi-event-title): Ditto. + (mixi-event-owner): Ditto. + (mixi-event-date): Ditto. + (mixi-event-place): Ditto. + (mixi-event-detail): Ditto. + (mixi-event-limit): Ditto. + (mixi-event-members): Ditto. + (mixi-event-set-time): Ditto. + (mixi-event-set-title): Ditto. + (mixi-event-set-owner): Ditto. + (mixi-event-set-date): Ditto. + (mixi-event-set-place): Ditto. + (mixi-event-set-detail): Ditto. + (mixi-event-set-limit): Ditto. + (mixi-event-set-members): Ditto. + (mixi-bbs-list-page): Rename from `mixi-topic-list-page'. + (mixi-bbs-list-regexp): Rename from `mixi-topic-list-regexp'. + (mixi-get-bbses): Rename from `mixi-get-topics'. + (mixi-new-bbs-list-page): Rename from `mixi-new-topic-list-page'. + (mixi-new-bbs-list-regexp): Rename from `mixi-new-topic-list-regexp'. + (mixi-get-new-bbses): Rename from `mixi-get-new-topics'. + (mixi-bbs-list-regexp): Follow the change above. + (mixi-get-bbses): Ditto. + (mixi-new-bbs-list-regexp): Ditto. + (mixi-get-new-bbses): Ditto. + (mixi-event-comment-list-page): New function. + (mixi-event-comment-list-regexp): New constant. + + * sb-mixi.el (shimbun-mixi-group-alist): Follow the change above. + (shimbun-mixi-make-subject): Ditto. + (shimbun-mixi-make-xref): Ditto. + (shimbun-mixi-get-headers): Ditto. + (shimbun-get-headers): Ditto. + (shimbun-mixi-make-body): New function. + (shimbun-article): Follow the change above. + +2006-11-27 OHASHI Akira + * sb-mixi.el (shimbun-mixi-get-headers): Don't quit even if there are comments which have already gotten. diff --git a/mixi.el b/mixi.el index 05f77f4..e0b360e 100644 --- a/mixi.el +++ b/mixi.el @@ -32,8 +32,8 @@ ;; * mixi-get-diaries ;; * mixi-get-new-diaries ;; * mixi-get-communities -;; * mixi-get-topics -;; * mixi-get-new-topics +;; * mixi-get-bbses +;; * mixi-get-new-bbses ;; * mixi-get-comments ;; * mixi-get-new-comments ;; * mixi-get-messages @@ -1411,38 +1411,262 @@ Increase this value when unexpected error frequently occurs." (signal 'wrong-type-argument (list 'mixi-topic-p topic))) (aset (cdr topic) 6 content)) -(defmacro mixi-topic-list-page (community) +;; Event object. +(defvar mixi-event-cache (make-hash-table :test 'equal)) +(defun mixi-make-event (community id) + "Return a event object." + (mixi-make-cache (list (mixi-community-id community) id) + (cons 'mixi-event (vector nil community id nil nil nil nil + nil nil nil nil)) + mixi-event-cache)) + +(defconst mixi-event-url-regexp + "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=[0-9]+\\)?&comm_id=\\([0-9]+\\)") + +(defun mixi-make-event-from-url (url) + "Return a event object from URL." + (when (string-match mixi-event-url-regexp url) + (let ((id (match-string 1 url)) + (community-id (match-string 3 url))) + (mixi-make-event (mixi-make-community community-id) id)))) + +(defmacro mixi-event-p (event) + `(eq (mixi-object-class ,event) 'mixi-event)) + +(defmacro mixi-event-page (event) + `(concat "/view_event.pl?id=" (mixi-event-id ,event) + "&comm_id=" (mixi-community-id (mixi-event-community ,event)))) + +(defconst mixi-event-time-regexp + " +\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü
+\\([0-9]+\\):\\([0-9]+\\)") +(defconst mixi-event-title-regexp + " \\([^<]+\\)") +(defconst mixi-event-owner-regexp + " \\(.*\\)") +(defconst mixi-event-date-regexp + "³«ºÅÆü»þ + + \\(.+\\) +") +(defconst mixi-event-place-regexp + "³«ºÅ¾ì½ê + + \\(.+\\) +") +(defconst mixi-event-detail-regexp + "¾ÜºÙ +
\\(.+\\)
") +(defconst mixi-event-limit-regexp + "Ê罸´ü¸Â + \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü") +(defconst mixi-event-members-regexp + "»²²Ã¼Ô + + + +") + +(defun mixi-event-realize (event) + "Realize a EVENT." + ;; FIXME: Check a expiration of cache? + (unless (mixi-object-realize-p event) + (with-mixi-retrieve (mixi-event-page event) + (if (string-match mixi-event-time-regexp buffer) + (mixi-event-set-time + event (encode-time 0 (string-to-number (match-string 5 buffer)) + (string-to-number (match-string 4 buffer)) + (string-to-number (match-string 3 buffer)) + (string-to-number (match-string 2 buffer)) + (string-to-number (match-string 1 buffer)))) + (signal 'error (list 'cannot-find-time event))) + (if (string-match mixi-event-title-regexp buffer) + (mixi-event-set-title event (match-string 1 buffer)) + (signal 'error (list 'cannot-find-title event))) + (if (string-match mixi-event-owner-regexp buffer) + (mixi-event-set-owner event + (mixi-make-friend (match-string 1 buffer) + (match-string 2 buffer))) + (signal 'error (list 'cannot-find-owner event))) + (if (string-match mixi-event-date-regexp buffer) + (mixi-event-set-date event (match-string 1 buffer)) + (signal 'error (list 'cannot-find-date event))) + (if (string-match mixi-event-place-regexp buffer) + (mixi-event-set-place event (match-string 1 buffer)) + (signal 'error (list 'cannot-find-place event))) + (if (string-match mixi-event-detail-regexp buffer) + (mixi-event-set-detail event (match-string 1 buffer)) + (signal 'error (list 'cannot-find-detail event))) + (when (string-match mixi-event-limit-regexp buffer) + (mixi-event-set-limit + event (encode-time 0 0 0 (string-to-number (match-string 3 buffer)) + (string-to-number (match-string 2 buffer)) + (string-to-number (match-string 1 buffer))))) + (if (string-match mixi-event-members-regexp buffer) + (mixi-event-set-members event (match-string 1 buffer)) + (signal 'error (list 'cannot-find-members event)))) + (mixi-object-touch event))) + +(defun mixi-event-community (event) + "Return the community of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aref (cdr event) 1)) + +(defun mixi-event-id (event) + "Return the id of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aref (cdr event) 2)) + +(defun mixi-event-time (event) + "Return the time of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (mixi-event-realize event) + (aref (cdr event) 3)) + +(defun mixi-event-title (event) + "Return the title of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (mixi-event-realize event) + (aref (cdr event) 4)) + +(defun mixi-event-owner (event) + "Return the owner of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (mixi-event-realize event) + (aref (cdr event) 5)) + +(defun mixi-event-date (event) + "Return the date of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (mixi-event-realize event) + (aref (cdr event) 6)) + +(defun mixi-event-place (event) + "Return the place of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (mixi-event-realize event) + (aref (cdr event) 7)) + +(defun mixi-event-detail (event) + "Return the detail of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (mixi-event-realize event) + (aref (cdr event) 8)) + +(defun mixi-event-limit (event) + "Return the limit of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (mixi-event-realize event) + (aref (cdr event) 9)) + +(defun mixi-event-members (event) + "Return the members of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (mixi-event-realize event) + (aref (cdr event) 10)) + +(defun mixi-event-set-time (event time) + "Set the time of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aset (cdr event) 3 time)) + +(defun mixi-event-set-title (event title) + "Set the title of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aset (cdr event) 4 title)) + +(defun mixi-event-set-owner (event owner) + "Set the owner of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (unless (mixi-friend-p owner) + (signal 'wrong-type-argument (list 'mixi-friend-p owner))) + (aset (cdr event) 5 owner)) + +(defun mixi-event-set-date (event date) + "Set the date of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aset (cdr event) 6 date)) + +(defun mixi-event-set-place (event place) + "Set the place of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aset (cdr event) 7 place)) + +(defun mixi-event-set-detail (event detail) + "Set the detail of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aset (cdr event) 8 detail)) + +(defun mixi-event-set-limit (event limit) + "Set the limit of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aset (cdr event) 9 limit)) + +(defun mixi-event-set-members (event members) + "Set the members of EVENT." + (unless (mixi-event-p event) + (signal 'wrong-type-argument (list 'mixi-event-p event))) + (aset (cdr event) 10 members)) + +;; Bbs. +(defmacro mixi-bbs-list-page (community) `(concat "/list_bbs.pl?page=%d" "&id=" (mixi-community-id ,community))) -(defconst mixi-topic-list-regexp - "") +(defconst mixi-new-bbs-list-regexp + "") -(defun mixi-get-new-topics (&optional max-numbers) +(defun mixi-get-new-bbses (&optional max-numbers) "Get new topics." - (let ((items (mixi-get-matched-items (mixi-new-topic-list-page) + (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page) max-numbers - mixi-new-topic-list-regexp))) + mixi-new-bbs-list-regexp))) (mapcar (lambda (item) - (mixi-make-topic (mixi-make-community (nth 1 item)) - (nth 0 item))) + (let ((name (nth 0 item))) + (when (string= name "bbs") + (setq name "topic")) + (let ((func (intern (concat "mixi-make-" name)))) + (funcall func (mixi-make-community (nth 2 item)) + (nth 1 item))))) items))) ;; Comment object. @@ -1546,6 +1770,32 @@ Increase this value when unexpected error frequently occurs." ") +(defun mixi-event-comment-list-page (event) + (concat "/view_event.pl?page=all" + "&id=" (mixi-event-id event) + "&comm_id=" (mixi-community-id (mixi-event-community event)))) + +;; FIXME: Split regexp to time, owner(id and nick) and contents. +(defconst mixi-event-comment-list-regexp + " +\\) +\\( + +\\(\\) + +") + (defun mixi-get-comments (parent &optional max-numbers) "Get comments of PARENT." (unless (mixi-object-p parent) diff --git a/sb-mixi.el b/sb-mixi.el index 3edc84e..e58123a 100644 --- a/sb-mixi.el +++ b/sb-mixi.el @@ -33,15 +33,15 @@ (defcustom shimbun-mixi-group-alist '(("new-diaries" . mixi-get-new-diaries) ("new-comments" . mixi-get-new-comments) - ("new-topics" . mixi-get-new-topics) + ("new-bbses" . mixi-get-new-bbses) ("messages" . mixi-get-messages) ("my-diaries" . "/home.pl")) "*An alist of mixi shimbun group definition. Each element looks like (NAME . URL) or (NAME . FUNCTION). NAME is a shimbun group name. URL is the URL for mixi access point of the group. When URL is friend's, get -his/her diaries as article. When community's, get its topics. When diary's -or topic's, get its comments. +his/her diaries as article. When community's, get its BBSes. When diary's +or BBS's, get its comments. FUNCTION is the function for getting articles." :group 'shimbun :type '(repeat (cons :fromat "%v" @@ -49,7 +49,7 @@ FUNCTION is the function for getting articles." (radio (string :tag "URL") (const :tag "New diaries" mixi-get-new-diaries) (const :tag "New comments" mixi-get-new-comments) - (const :tag "New topics" mixi-get-new-topics) + (const :tag "New BBSes" mixi-get-new-bbses) (const :tag "Messages" mixi-get-messages) (function :tag "Other function"))))) @@ -60,7 +60,7 @@ FUNCTION is the function for getting articles." :type 'integer) (defcustom shimbun-mixi-get-comment-p t - "*If non-nil, get diaries or topics together with its comments." + "*If non-nil, get diaries or BBSes together with its comments." :group 'shimbun :type 'boolean) @@ -69,9 +69,12 @@ FUNCTION is the function for getting articles." (defun shimbun-mixi-make-subject (object) (let ((class (mixi-object-class object))) - (if (eq class 'mixi-comment) - (concat "Re: " (mixi-object-title (mixi-comment-parent object))) - (mixi-object-title object)))) + (cond ((eq class 'mixi-comment) + (concat "Re: " (shimbun-mixi-make-subject + (mixi-comment-parent object)))) + ((eq class 'mixi-event) + (concat "[¥¤¥Ù¥ó¥È]" (mixi-object-title object))) + (t (mixi-object-title object))))) (defun shimbun-mixi-make-from (object) (let ((owner (mixi-object-owner object))) @@ -107,12 +110,33 @@ FUNCTION is the function for getting articles." (mixi-expand-url (mixi-diary-page object))) ((eq class 'mixi-topic) (mixi-expand-url (mixi-topic-page object))) + ((eq class 'mixi-event) + (mixi-expand-url (mixi-event-page object))) ((eq class 'mixi-comment) (concat (shimbun-mixi-make-xref (mixi-comment-parent object)) "#comment")) ((eq class 'mixi-message) (mixi-expand-url (mixi-message-page object)))))) +(defun shimbun-mixi-make-body (object) + (let ((class (mixi-object-class object))) + (if (eq class 'mixi-event) + (let ((limit (mixi-event-limit object))) + (setq limit (if limit + (format-time-string "%Yǯ%m·î%dÆü" limit) + "»ØÄê¤Ê¤·")) + (concat "
³«ºÅÆü»þ¡§
" + "
" (mixi-event-date object) "
" + "
³«ºÅ¾ì½ê¡§
" + "
" (mixi-event-place object) "
" + "
¾ÜºÙ¡§
" + "
" (mixi-event-detail object) "
" + "
Ê罸´ü¸Â¡§
" + "
" limit "
" + "
»²²Ã¼Ô¡§
" + "
" (mixi-event-members object) "
")) + (mixi-object-content object)))) + (defun shimbun-mixi-get-headers (shimbun objects &optional range) (when objects (let (headers) @@ -137,7 +161,8 @@ FUNCTION is the function for getting articles." headers) (when (and shimbun-mixi-get-comment-p (or (eq class 'mixi-diary) - (eq class 'mixi-topic))) + (eq class 'mixi-topic) + (eq class 'mixi-event))) (let ((comments (mixi-get-comments object range))) (mapc (lambda (header) (push header headers)) @@ -158,8 +183,10 @@ FUNCTION is the function for getting articles." (cond ((eq class 'mixi-friend) (setq objects (mixi-get-diaries object range))) ((eq class 'mixi-community) - (setq objects (mixi-get-topics object range))) - ((or (eq class 'mixi-diary) (eq class 'mixi-topic)) + (setq objects (mixi-get-bbses object range))) + ((or (eq class 'mixi-diary) + (eq class 'mixi-topic) + (eq class 'mixi-event)) (setq objects (mixi-get-comments object range))) (t (error (concat (symbol-name class) " is not supported yet."))))) @@ -191,7 +218,7 @@ FUNCTION is the function for getting articles." (article (if (string-match "#comment$" url) (shimbun-comment-article url header) ;; FIXME: Concat community information? - (mixi-object-content + (shimbun-mixi-make-body (mixi-make-object-from-url url))))) (when (stringp article) (insert article)))
 \\(.+\\)
+\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü
+\\([0-9]+\\):\\([0-9]+\\)
+\\(
\\) +[^<]+ : +\\(.*\\) + +
+ + +
\\(.+\\)
+