Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Created March 30, 2013 20:54
Show Gist options
  • Save Idorobots/5278294 to your computer and use it in GitHub Desktop.
Save Idorobots/5278294 to your computer and use it in GitHub Desktop.
Export your RSS feeds from Google Reader into Emacs News Ticker compatible format.
(require 'xml)
(defun assoc-or-error (what where &optional err-string)
(or (assoc what where)
(error (or err-string "Suddenly errors! Thousands of them!"))))
(defun google-reader-to-newsticker (filename)
"Parses google-reader subscription XML and returns newsticker compatible feed alist."
(with-temp-buffer
(insert-file-contents filename)
(let* ((opml (assoc-or-error 'opml
(xml-parse-region (point-min) (point-max))
"Not a valid feed XML!"))
(body (assoc-or-error 'body
opml
"Not a valid feed XML!"))
(outlines (delq nil
(map 'list
(lambda (element)
(and (consp element)
(equal (car element) 'outline)
element))
body)))
(alist (map 'list
(lambda (outline)
(let ((title (assoc-or-error 'title
outline
"No title in an outline - malformed feed XML?"))
(feed (assoc-or-error 'xmlUrl
outline
"No feed link in an outline - check your feed XML!")))
(list (cdr title) (cdr feed))))
(map 'list
#'cadr
outlines))))
alist)))
@afeicool
Copy link

afeicool commented Apr 9, 2013

nice

@0mid
Copy link

0mid commented Aug 3, 2013

Thanks for writing this conversion code from Greader to Emacs News Ticker (and the guide http://idorobots.org/2013/03/30/greader-alternative). After adding two parentheses to the last line (which I think were missing because otherwise we would get an unbalanced parentheses error) and running

(setq newsticker-url-list
  (google-reader-to-newsticker "~/temp/subscriptions.xml"))

I get the following error:

Debugger entered--Lisp error: (error "`let' bindings can have only one value-form" alist (map (quote list) (function (lambda ... ...))) alist)
  (let* ((opml (assoc-or-error (quote opml) (xml-parse-region (point-min) (point-max)) "Not a valid feed XML!")) (body (assoc-or-error (quote body) opml "Not a valid feed XML!")) (outlines (delq nil (map (quote list) (function (lambda (element) (and ... ... element))) body))) (alist (map (quote list) (function (lambda (outline) (let (...) (map ... ... outlines))))) alist)))
  (progn (insert-file-contents filename) (let* ((opml (assoc-or-error (quote opml) (xml-parse-region (point-min) (point-max)) "Not a valid feed XML!")) (body (assoc-or-error (quote body) opml "Not a valid feed XML!")) (outlines (delq nil (map (quote list) (function (lambda ... ...)) body))) (alist (map (quote list) (function (lambda (outline) (let ... ...)))) alist))))
  (unwind-protect (progn (insert-file-contents filename) (let* ((opml (assoc-or-error (quote opml) (xml-parse-region (point-min) (point-max)) "Not a valid feed XML!")) (body (assoc-or-error (quote body) opml "Not a valid feed XML!")) (outlines (delq nil (map (quote list) (function ...) body))) (alist (map (quote list) (function (lambda ... ...))) alist)))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents filename) (let* ((opml (assoc-or-error (quote opml) (xml-parse-region ... ...) "Not a valid feed XML!")) (body (assoc-or-error (quote body) opml "Not a valid feed XML!")) (outlines (delq nil (map ... ... body))) (alist (map (quote list) (function ...)) alist)))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
  (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents filename) (let* ((opml (assoc-or-error ... ... "Not a valid feed XML!")) (body (assoc-or-error ... opml "Not a valid feed XML!")) (outlines (delq nil ...)) (alist (map ... ...) alist)))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
  google-reader-to-newsticker("~/temp/subscriptions.xml")
  (setq newsticker-url-list (google-reader-to-newsticker "~/temp/subscriptions.xml"))
  eval-region(20509 20594 t (lambda (ignore) (goto-char 20594) (quote (setq newsticker-url-list (google-reader-to-newsticker "~/temp/subscriptions.xml")))))  ; Reading at buffer position 20594
  apply(eval-region (20509 20594 t (lambda (ignore) (goto-char 20594) (quote (setq newsticker-url-list (google-reader-to-newsticker "~/temp/subscriptions.xml"))))))
  eval-defun-2()
  eval-defun(nil)
  call-interactively(eval-defun nil nil)

Am I missing something here?

@Idorobots
Copy link
Author

Weird, on my end it seems to be working and no parentheses are missing.
On a side note, a probably better solution is to use the builtin Newsticker importer - newsticker-opml-import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment