Created
January 14, 2013 12:58
-
-
Save anonymous/4529894 to your computer and use it in GitHub Desktop.
Some code to make all doodle dates in a given doodle available as timestamps ready for inclusion in an org-mode buffer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun youngfrog/doodle-list-time-stamps (url) | |
"Return a list of org time-stamps for doodle at URL" | |
(let (curr-date acc) | |
(with-current-buffer (url-retrieve-synchronously url) | |
(goto-char (point-min)) | |
(search-forward "\"optionsText\":") | |
(when (not (looking-at "\\[")) | |
(pop-to-buffer (current-buffer)) | |
(error "Unexpected character: %s (expected [)" (char-to-string (char-after)))) | |
(narrow-to-region (point) (progn (forward-sexp) (point))) | |
(goto-char (point-min)) | |
(while (re-search-forward "\"\\([^\"]+\\)\"" nil t) | |
(add-to-list 'acc (youngfrog/doodle-from-date-to-org-ts (match-string 1))))) | |
acc)) | |
(defun youngfrog/doodle-from-date-to-org-ts (date) | |
"Convert a date from doodle to one for `org-mode'. | |
DATE should be of the form: \"Tuesday, February 19, 2013 2:00 PM | |
- 4:00 PM\", the part \" - 4:00 PM\" being optional." | |
;; This functions lets org-read-date-analyze do the job. It might | |
;; sound overkill, but we would need to deal with the AM/PM | |
;; notation, which org-mode does already. | |
(setq date (with-temp-buffer ;; make the date recognized by | |
;; org-read-date-analyze by removing | |
;; spaces from the time spec. | |
(insert date) | |
(goto-char (point-min)) | |
(re-search-forward "\\( \\)[AP]M") | |
(replace-match "" t t nil 1) | |
(while (search-forward " " nil t) | |
(replace-match "")) | |
(buffer-string))) | |
(let (org-last-inserted-timestamp ; don't let org-insert-time-stamp change this globally. | |
org-end-time-was-given) ; modified by org-read-date-analyze | |
(with-temp-buffer | |
(org-insert-time-stamp (apply 'encode-time (org-read-date-analyze date nil nil)) | |
t | |
nil | |
nil nil (list org-end-time-was-given)) | |
(buffer-string)))) | |
(defun youngfrog/doodle-insert-time-stamps (url) | |
"Insert the list of org timestamps for doodle at URL" | |
(interactive "sAddress of the doodle: ") | |
(insert (mapconcat 'identity (nreverse (youngfrog/doodle-list-time-stamps url)) ",\n"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment