Skip to content

Instantly share code, notes, and snippets.

@cadadr
Created October 14, 2021 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cadadr/0d7fcc98161ec66142fd7ffc8eaa65cc to your computer and use it in GitHub Desktop.
Save cadadr/0d7fcc98161ec66142fd7ffc8eaa65cc to your computer and use it in GitHub Desktop.
OPML-to-sexp converter for elfeed

This will convert your OPML to an sexp that can be used to set up feeds for elfeed. It'll convert categories (likely, folders, in your feed reader) to tags.

You will need to keep gk-elfeed-feeds-with-category around after doing the conversion.

A nice way to use this is to run it with C-u M-x pp-eval-last-sexp RET C-M-b C-j C-j and manually reformat the resulting output.

You'll want to have something like paredir or smartparens set up to work with that sort of large sexp.

(defun assoca (keyseq list)
(let ((ks (if (listp keyseq) keyseq (list keyseq)))
(ret list))
(dolist (k ks ret)
(setq ret (cdr (assoc k ret))))))
(defun gk-elfeed-feeds-with-category (category &rest feeds)
(declare (indent defun))
(mapcar (lambda (feed)
(append (if (listp feed) feed (list feed))
(if (listp category) category (list category))))
feeds))
(defun gk-elfeed-import-from-feeder-OPML (file)
(cons
'setf
(cons
'elfeed-feeds
(list
(cons
'cl-concatenate
(cons
''list
(cl-remove-if
#'not
(mapcar
(lambda (cat)
(let (tag feeds)
(when (listp cat)
(when (eq 'outline (car cat))
(setq tag (intern (downcase (assoca 'title (cadr cat))))
feeds (cl-remove-if-not #'listp (cdddr cat)))
`(gk-elfeed-feeds-with-category
',tag
,@(mapcar (lambda (f) (assoca 'xmlUrl (cadr f))) feeds))))))
(assoca
'(opml body)
(xml-parse-file file))))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment