Skip to content

Commit

Permalink
Various small cleanups.
Browse files Browse the repository at this point in the history
git-svn-id: https://ljupdate.googlecode.com/svn/trunk@16 e25b6a91-9619-0410-a269-c760fbc1eb27
  • Loading branch information
hober0 committed Jul 24, 2007
1 parent 0d0092a commit 98bc219
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 109 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ EMACS=emacs -q --no-site-file

## Building

SOURCE=lj-acct.el lj-compat.el lj-compose.el lj-custom.el lj-fill.el \
lj-login.el lj-pcomplete.el lj-protocol.el lj-util.el lj-edit.el
SOURCE=lj-acct.el lj-compat.el lj-compose.el lj-custom.el lj-edit.el \
lj-fill.el lj-login.el lj-pcomplete.el lj-protocol.el lj-util.el
TARGET=$(patsubst %.el,%.elc, $(SOURCE) ljupdate.el)
TARBALL=ljupdate.tar.gz

Expand Down
22 changes: 11 additions & 11 deletions lj-compose.el
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@
(server (lj-compose-fetch-field "Server"))
(user (lj-compose-fetch-field "User"))

;; The current time -- or use the specified time if it exists
(time-field (lj-compose-fetch-field "Time"))
(timestamp (if (eq nil time-field)
()
(date-to-time (concat time-field " " (cadr (current-time-zone))))))
;; The current time -- or use the specified time if it exists
(time-field (lj-compose-fetch-field "Time"))
(timestamp (if (eq nil time-field)
()
(date-to-time (concat time-field " " (cadr (current-time-zone))))))

(time (split-string (format-time-string "%Y:%m:%d:%H:%M" timestamp) "[:]"))
(year (pop time))
(month (pop time))
Expand All @@ -136,9 +136,9 @@
(add-to-list 'request (cons "user" user))
(let ((itemid (lj-compose-fetch-field "Itemid")))
(if itemid
(progn (add-to-list 'request (cons "itemid" itemid))
(add-to-list 'request '("mode" . "editevent")))
(add-to-list 'request '("mode" . "postevent"))))
(progn (add-to-list 'request (cons "itemid" itemid))
(add-to-list 'request '("mode" . "editevent")))
(add-to-list 'request '("mode" . "postevent"))))
(let ((subject (lj-compose-fetch-field "Subject")))
(when subject
(add-to-list 'request (cons "subject" subject))))
Expand Down Expand Up @@ -210,7 +210,7 @@
(message "Submitting to `%s' as `%s'. Please wait." server user)

(let ((response (lj-protocol-send-request server request)))
(set-buffer buf) ; return to the *LiveJournal* buffer
(set-buffer buf) ; return to the *LiveJournal* buffer
(if (and (hash-table-p response)
(string= (gethash "success" response) "OK"))
(progn
Expand Down Expand Up @@ -322,7 +322,7 @@ in `html-mode'.")
(kbd "C-c C-f C-c") (kbd "C-c C-f C-d") (kbd "C-c C-f C-f")
(kbd "C-c C-f C-k") (kbd "C-c C-f C-n") (kbd "C-c C-f C-o")
(kbd "C-c C-f C-r") (kbd "C-c C-f C-t") (kbd "C-c C-f C-u")
(kbd "C-c C-f <RET>") ; (kbd "C-c C-f <TAB>")
(kbd "C-c C-f <RET>") ; (kbd "C-c C-f <TAB>")
(kbd "C-c C-j") (kbd "C-c C-l") (kbd "C-c C-n")
(kbd "C-c C-q") (kbd "C-c C-r") (kbd "C-c C-t")
(kbd "C-c C-u") (kbd "C-c C-v") (kbd "C-c C-w")
Expand Down
195 changes: 99 additions & 96 deletions lj-edit.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,33 @@
(interactive)
(message (concat "Editing id: " edit-itemid))
(let* ((edit-server (or lj-last-server lj-default-server
"www.livejournal.com"))
(edit-username (or lj-last-username lj-default-username ""))
(edit-request (list '("mode" . "getevents")
'("auth_method" . "challenge")
'("ver" . "1")
'("selecttype" . "one")
)))
(add-to-list 'edit-request (cons "itemid" edit-itemid))
(setq edit-challenge (lj-getchallenge edit-server))
(if (string= edit-username "")
(setq edit-username (read-from-minibuffer (format "Username @%s: " edit-server))))
"www.livejournal.com"))
(edit-username (or lj-last-username lj-default-username ""))
(edit-request (list '("mode" . "getevents")
'("auth_method" . "challenge")
'("ver" . "1")
'("selecttype" . "one")
(cons "itemid" edit-itemid)
))
(edit-challenge (lj-getchallenge edit-server)))
(when (string= edit-username "")
(setq edit-username (read-from-minibuffer (format "Username @%s: " edit-server))))
(add-to-list 'edit-request (cons "user" edit-username))
(add-to-list 'edit-request (cons "auth_challenge" edit-challenge))
(add-to-list 'edit-request
(cons "auth_response"
(lj-md5 (concat edit-challenge (lj-password edit-server edit-username)))))
(add-to-list 'edit-request (cons "user" lj-last-username))
(cons "auth_response"
(lj-md5 (concat edit-challenge (lj-password edit-server edit-username)))))
(let ((edit-response (lj-protocol-send-request edit-server edit-request)))
(with-output-to-temp-buffer "lj-list"
(set-buffer "lj-list")
;; (lj-list-props response)
(if (not (eq (get-buffer "*LiveJournal*") nil))
(kill-buffer (get-buffer "*LiveJournal*")))
(lj-compose)
(goto-char (- 1 (lj-compose-find-separator)))
(lj-add-props edit-response edit-server edit-username)
(goto-char (+ 1 (lj-compose-find-separator)))
(insert (replace-regexp-in-string "\r" "" (lj-html-decode-string (gethash "events_1_event" edit-response))))))))
;; (lj-list-props response)
(if (not (eq (get-buffer "*LiveJournal*") nil))
(kill-buffer (get-buffer "*LiveJournal*")))
(lj-compose)
(goto-char (- 1 (lj-compose-find-separator)))
(lj-add-props edit-response edit-server edit-username)
(goto-char (+ 1 (lj-compose-find-separator)))
(insert (replace-regexp-in-string "\r" "" (lj-html-decode-string (gethash "events_1_event" edit-response))))))))

(defun lj-add-prop (prop value)
(let ((found-field (message-position-on-field prop)))
Expand All @@ -90,22 +90,22 @@

(defun lj-add-props-helper (response n)
(if (> n 0)
(progn
(let ((prop_name (gethash (concat "prop_" (number-to-string n) "_name") response))
(prop_value (gethash (concat "prop_" (number-to-string n) "_value") response)))
(cond ((string= prop_name "current_mood") (lj-add-prop "Mood" prop_value))
((string= prop_name "current_music") (lj-add-prop "Music" prop_value))
((string= prop_name "taglist") (lj-add-prop "Tags" prop_value))
((string= prop_name "picture_keyword") (lj-add-prop "Picture" prop_value))
((string= prop_name "picture_keyword") (lj-add-prop "Picture" prop_value))
((and (string= prop_name "opt_nocomments") (string= prop_value "1"))
(lj-add-prop "Allow-Comments" "no"))
((and (string= prop_name "opt_noemail") (string= prop_value "1"))
(lj-add-prop "Receive-Mail-Notification" "no"))
))
(lj-add-props-helper response (- n 1)))))

(defun lj-add-props (response edit-server edit-username)
(progn
(let ((prop_name (gethash (concat "prop_" (number-to-string n) "_name") response))
(prop_value (gethash (concat "prop_" (number-to-string n) "_value") response)))
(cond ((string= prop_name "current_mood") (lj-add-prop "Mood" prop_value))
((string= prop_name "current_music") (lj-add-prop "Music" prop_value))
((string= prop_name "taglist") (lj-add-prop "Tags" prop_value))
((string= prop_name "picture_keyword") (lj-add-prop "Picture" prop_value))
((string= prop_name "picture_keyword") (lj-add-prop "Picture" prop_value))
((and (string= prop_name "opt_nocomments") (string= prop_value "1"))
(lj-add-prop "Allow-Comments" "no"))
((and (string= prop_name "opt_noemail") (string= prop_value "1"))
(lj-add-prop "Receive-Mail-Notification" "no"))
))
(lj-add-props-helper response (- n 1)))))

(defun lj-add-props (response edit-server edit-username)
(let ((subject (gethash "events_1_subject" response)))
(when subject
(lj-add-prop "Subject" subject)))
Expand All @@ -116,17 +116,17 @@
(when itemid
(lj-add-prop "Itemid" itemid)))

(let* ((access (gethash "events_1_security" response))
(allowmask (gethash "events_1_allowmask" response)))
(if (stringp access)
(cond ((string-match "public" access)
(lj-add-prop "Access" "public"))
((string-match "private" access)
(lj-add-prop "Access" "private"))
((string-match "usemask" access)
(if (eq (truncate (log (string-to-number allowmask) 2)) 0)
(lj-add-prop "Access" "friends")
(lj-add-prop "Access" (car (rassoc (truncate (log (string-to-number allowmask) 2)) (lj-user-get edit-server edit-username :friends-groups)))))))))
(let* ((access (gethash "events_1_security" response))
(allowmask (gethash "events_1_allowmask" response)))
(if (stringp access)
(cond ((string-match "public" access)
(lj-add-prop "Access" "public"))
((string-match "private" access)
(lj-add-prop "Access" "private"))
((string-match "usemask" access)
(if (eq (truncate (log (string-to-number allowmask) 2)) 0)
(lj-add-prop "Access" "friends")
(lj-add-prop "Access" (car (rassoc (truncate (log (string-to-number allowmask) 2)) (lj-user-get edit-server edit-username :friends-groups)))))))))
(lj-add-props-helper response (string-to-number (gethash "prop_count" response))))
;;;###autoload
;; (defun lj-edit-submit ()
Expand All @@ -139,13 +139,13 @@
;; ;; Some convenience variables for oft-used headers
;; (server (lj-compose-fetch-field "Server"))
;; (user (lj-compose-fetch-field "User"))
;; (itemid (lj-compose-fetch-field "Itemid"))
;; (itemid (lj-compose-fetch-field "Itemid"))
;; ;; The current time -- or use the specified time if it exists
;; (time (lj-compose-fetch-field "Time"))
;; (timestamp (if (eq nil time)
;; ()
;; (date-to-time (concat time " " (cadr (current-time-zone))))))
;; (time (lj-compose-fetch-field "Time"))
;; (timestamp (if (eq nil time)
;; ()
;; (date-to-time (concat time " " (cadr (current-time-zone))))))

;; (time (split-string (format-time-string "%Y:%m:%d:%H:%M" timestamp) "[:]"))
;; (year (pop time))
;; (month (pop time))
Expand All @@ -161,7 +161,7 @@
;; (request (list '("mode" . "editevent")
;; '("auth_method" . "challenge")
;; '("ver" . "1")
;; (cons "itemid" itemid)
;; (cons "itemid" itemid)
;; (cons "year" year)
;; (cons "mon" month)
;; (cons "day" day)
Expand Down Expand Up @@ -249,66 +249,69 @@
;; (message "Posting to %s failed!" server)))
;; nil))))

(defun lj-html-decode-string (in_string)
(defun lj-html-decode-string (string)
(interactive)
(let ((in_string (replace-regexp-in-string "%\\([0-9A-F]\\{2\\}\\)" (lambda (my_match) (char-to-string (string-to-number (substring my_match 1) 16))) in_string)))
(replace-regexp-in-string "+" " " in_string)))
(let ((string (replace-regexp-in-string "%\\([0-9A-F]\\{2\\}\\)" (lambda (match) (char-to-string (string-to-number (substring match 1) 16))) string)))
(replace-regexp-in-string "+" " " string)))

(defun lj-list-props (response n)
(interactive)
(if (> n 0)
(progn
(insert (gethash (concat "prop_" (number-to-string n) "_name") response))
(insert "\t")
(insert (gethash (concat "prop_" (number-to-string n) "_value") response))
(insert "\n")
(lj-list-props response (- n 1)))))
(progn
(insert (gethash (concat "prop_" (number-to-string n) "_name") response))
(insert "\t")
(insert (gethash (concat "prop_" (number-to-string n) "_value") response))
(insert "\n")
(lj-list-props response (- n 1)))))

(defun lj-insert-entry-into-entry-list (hash n)
(lexical-let* ((event_string (concat "events_" (number-to-string n)))
(event_subject (concat event_string "_subject"))
(event_time (concat event_string "_eventtime"))
(event_itemid_string (concat event_string "_itemid"))
(event_itemid (gethash event_itemid_string hash))
(button_start -1)
(button_end -1)
(which_event n))
(event_subject (concat event_string "_subject"))
(event_time (concat event_string "_eventtime"))
(event_itemid_string (concat event_string "_itemid"))
(event_itemid (gethash event_itemid_string hash))
(button_start -1)
(button_end -1)
(which_event n))
(if (<= n (string-to-number (gethash "events_count" hash)))
(progn
(insert-button (concat (gethash event_time hash) " - "
(if (gethash event_subject hash)
(gethash event_subject hash)
"(no subject)")) 'action (lambda (event) (lj-edit-post event_itemid)))
(insert "\n");
(lj-insert-entry-into-entry-list hash (+ n 1))))))
(progn
(insert-button (concat (gethash event_time hash) " - "
(if (gethash event_subject hash)
(gethash event_subject hash)
"(no subject)")) 'action (lambda (event) (lj-edit-post event_itemid)))
(insert "\n")
(lj-insert-entry-into-entry-list hash (+ n 1))))))

(defun lj-get-last-n (n)
(let* ((server (or lj-last-server lj-default-server
"www.livejournal.com"))
(username (or lj-last-username lj-default-username ""))
(request (list '("mode" . "getevents")
'("auth_method" . "challenge")
'("ver" . "1")
'("selecttype" . "lastn")
)))
(setq challenge (lj-getchallenge server))
(if (string= username "")
(setq username (read-from-minibuffer (format "Username @%s: " server))))
(add-to-list 'request (cons "howmany" (number-to-string n)))
"www.livejournal.com"))
(username (or lj-last-username lj-default-username ""))
(request (list '("mode" . "getevents")
'("auth_method" . "challenge")
'("ver" . "1")
'("selecttype" . "lastn")
(cons "howmany" (number-to-string n))))
(challenge (lj-getchallenge server)))
(when (string= username "")
(setq username (read-from-minibuffer (format "Username @%s: " server))))
(add-to-list 'request (cons "user" username))
(add-to-list 'request (cons "auth_challenge" challenge))
(add-to-list 'request
(cons "auth_response"
(lj-md5 (concat challenge (lj-password server username)))))
(add-to-list 'request (cons "user" lj-last-username))
(let ((response (lj-protocol-send-request server request)))
(with-output-to-temp-buffer "lj-list"
(set-buffer "lj-list")
(lj-insert-entry-into-entry-list response 1)
(print-help-return-message)))))
(set-buffer "lj-list")
(lj-insert-entry-into-entry-list response 1)
(print-help-return-message)))))

;;;###autoload
(defun lj-browse-entries ()
(interactive)
(lj-get-last-n 10))

(provide 'lj-edit)
(provide 'lj-edit)

(provide 'lj-edit)

;;; lj-edit.el ends here

0 comments on commit 98bc219

Please sign in to comment.