emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Arun Persaud <apersaud@lbl.gov>
To: emacs-orgmode@gnu.org
Subject: my setup for "remember the milk" (one way import to org-mode via org-feed.el)
Date: Sun, 04 Mar 2012 15:48:19 -0800	[thread overview]
Message-ID: <4F53FF43.4090402@lbl.gov> (raw)

Hi

I recently needed to add entries from "remember the milk"(RTM)[1] to my
org files... I found a script that converts to an orgfile[2], but also
the standard org-feed.el that can handle atom feeds. I played around a
bit with the latter and came up with the functions below that parse the
atom feed from RTM and also parse things like the due-date, tags, etc.

I also filter the feed by only including items that have a due date set
via the filter function.

Perhaps this is interesting for someone else, so I thought I post it
here. I could also upload it to Worg if there is interest, but am not
sure where it would go (don't use Worg that much lately).

cheers

Arun

[1] www.rememberthemilk.com/
[2] https://gist.github.com/1379125

; set up RTM
(defun org-feed-parse-RTM-entry (entry)
  "Parse the `:item-full-text' as a sexp and create new properties."
  (let ((xml (car (read-from-string (plist-get entry :item-full-text)))))
    ;; Get first <link href='foo'/>.
    (setq entry (plist-put entry :link
                           (xml-get-attribute
                            (car (xml-get-children xml 'link))
                            'href)))
    ;; Add <title/> as :title.
    (setq entry (plist-put entry :title
                           (xml-substitute-special
                            (car (xml-node-children
                                  (car (xml-get-children xml 'title)))))))
    ;; look for some other information that's in the content of the entry
    ;; the structure looks something like:
    ;; <content><div>   <div item> <span itemname></span><span
itemvalue></span></div>...
    (let* ((content (car (xml-get-children xml 'content)))
	   (main  (car (xml-get-children content 'div)))
	   (items (xml-get-children main 'div)))
      (when items
	; iterate over all items and check for certain classes
        (while items
	  (setq item (car items))
	  ; get the second span entry
	  (setq valuesub (car (cdr (xml-node-children item))))
	     (cond
	      ((string= (xml-get-attribute item 'class) "rtm_due")
	       (setq entry (plist-put entry :due (car (xml-node-children
valuesub))))
	       (setq mydate (car (xml-node-children valuesub)))
	       (if (string= mydate "never")
		   nil
		 (progn
		  (string-match "^\\([a-zA-Z]*\\) \\([0-9]*\\) \\([a-zA-Z]*\\)
\\([0-9]*\\)$" mydate)
		  (setq mydate (concat "20" (match-string 4 mydate) " " (match-string
3 mydate) " " (match-string 2 mydate) " 00:00:01"))
		  (setq mydate (parse-time-string mydate))
		  (setq mydate (apply #'encode-time mydate))
		  (setq mydate (format-time-string (car org-time-stamp-formats) mydate))
		  (setq entry (plist-put entry :dueorgformat mydate)))))
	      ((string= (xml-get-attribute item 'class) "rtm_tags")
	       (setq entry (plist-put entry :tags (car (xml-node-children
valuesub)))))
	      ((string= (xml-get-attribute item 'class) "rtm_time_estimate")
	       (setq entry (plist-put entry :timeestimate (car
(xml-node-children valuesub)))))
	      ((string= (xml-get-attribute item 'class) "rtm_priority")
	       (setq entry (plist-put entry :priority (car (xml-node-children
valuesub)))))
	      ((string= (xml-get-attribute item 'class) "rtm_location")
	       (setq entry (plist-put entry :location (car (xml-node-children
valuesub))))))
	  (setq items (cdr items))
	  )))
    entry))

(defun org-feed-RTM-filter-non-scheduled (entry)
  "filter out all entries that don't have a due date set"
  (if (string= (plist-get entry :due) "never")
      nil
    entry))

(setq org-feed-alist
      '(("Remember The Milk"
	 "<add your link to the RTM atom feed here>"
         "~/org/RTM.org"
         "Remember The Milk"
	 :parse-feed org-feed-parse-atom-feed
	 :parse-entry org-feed-parse-RTM-entry
         :template "* TODO %title\n SCHEDULED:%dueorgformat\n Due:
%due\n Location: %location\n Priority:%priority\n Tags:%tags\n %a\n "
	 :filter org-feed-RTM-filter-non-scheduled
         )))

;;* rtm feed timer
(run-at-time 3600 3600 'org-feed-update-all)

                 reply	other threads:[~2012-03-04 23:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F53FF43.4090402@lbl.gov \
    --to=apersaud@lbl.gov \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).