1
0
Fork 0
elfeed-export/elfeed-export.el

94 lines
3.1 KiB
EmacsLisp
Raw Normal View History

;;; elfeed-export.el --- Elfeed database export -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Bram Schoenmakers
;; Author: Bram Schoenmakers <me@bramschoenmakers.nl>
;; Maintainer: Bram Schoenmakers <me@bramschoenmakers.nl>
;; Created: 1 August 2024
;; Package-Version: 0.1
;; Package-Requires: ((emacs "29.1"))
;; Keywords:
;; URL:
;; This file is not part of GNU Emacs.
;; MIT License
;; Copyright (c) 2024 Bram Schoenmakers
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;; The above copyright notice and this permission notice shall be included in all
;; copies or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;; Commentary:
;;; Code:
2024-08-01 21:17:54 +00:00
(require 'elfeed)
2024-08-01 20:05:19 +00:00
(defcustom elfeed-export-fields
'((title . elfeed-entry-title)
(date . elfeed-export--entry-date)
(url . elfeed-entry-link)
(tags . elfeed-entry-tags)
(feed-title . elfeed-export--feed-title)
(feed . elfeed-export--entry-feed)
(content . elfeed-export--entry-content))
"Which fields to export per entry and a function to obtain the value.
The function takes an entry argument for extracting the desired value."
:type 'alist
:group 'elfeed-export)
(defun elfeed-export--entry-date (entry)
(format-time-string "%F %T" (elfeed-entry-date entry)))
(defun elfeed-export--feed-title (entry)
(elfeed-feed-title (elfeed-entry-feed entry)))
(defun elfeed-export--entry-feed (entry)
(elfeed-feed-url (elfeed-entry-feed entry)))
(defun elfeed-export--entry-content (entry)
(elfeed-deref (elfeed-entry-content entry)))
2024-08-01 20:03:45 +00:00
(defun elfeed-export--entry-to-alist (entry)
(remove nil
(mapcar (lambda (field)
(cons (symbol-name (car field))
(funcall (cdr field) entry)))
elfeed-export-fields)))
2024-08-01 20:32:25 +00:00
(defun elfeed-export--entries ()
(let ((entries)
(feeds (elfeed-feed-list)))
2024-08-01 20:32:25 +00:00
(dolist (feed feeds)
(setq entries
(append entries
(elfeed-feed-entries feed))))
(mapcar #'elfeed-export--entry-to-alist entries)))
2024-08-01 20:32:25 +00:00
(defun elfeed-export-to-json ()
(json-encode (elfeed-export--entries)))
(defun elfeed-export-to-file (path)
(interactive "F")
(write-region (elfeed-export-to-json) nil path nil nil nil t))
(provide 'elfeed-export)
;;; elfeed-export.el ends here