commit 8624727b9327f0c63d3afe2560489fb91a239eef Author: Bram Schoenmakers Date: Thu Aug 1 21:55:06 2024 +0200 Initial commit of Emacs package to export the Elfeed database to JSON diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..9b19403 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 - 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. diff --git a/elfeed-export.el b/elfeed-export.el new file mode 100644 index 0000000..50ca6bc --- /dev/null +++ b/elfeed-export.el @@ -0,0 +1,80 @@ +;;; elfeed-export.el --- Elfeed database export -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Bram Schoenmakers + +;; Author: Bram Schoenmakers +;; Maintainer: Bram Schoenmakers +;; 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: + +(defcustom elfeed-export-include + '(title date url tags feed-title feed content) + "Which fields to export per entry." + :group 'elfeed-export) + +(defun elfeed-export-entry-to-alist (entry) + (let ((feed (elfeed-entry-feed entry))) + (remove nil + (list + (when (memq 'title elfeed-export-include) + (cons "title" (elfeed-entry-title entry))) + (when (memq 'date elfeed-export-include) + (cons "date" (format-time-string "%F %T" (elfeed-entry-date entry)))) + (when (memq 'url elfeed-export-include) + (cons "url" (elfeed-entry-link entry))) + (when (memq 'tags elfeed-export-include) + (cons "tags" (elfeed-entry-tags entry))) + (when (memq 'feed-title elfeed-export-include) + (cons "feed-title" (elfeed-feed-title feed))) + (when (memq 'feed elfeed-export-include) + (cons "feed" (elfeed-feed-url feed))) + (when (memq 'content elfeed-export-include) + (cons "content" (elfeed-deref (elfeed-entry-content entry)))))))) + +(defun elfeed-export-to-json () + (let ((entries) + (feeds (elfeed-feed-list))) + (dolist (feed (seq-take feeds 1)) + (setq entries + (append entries + (elfeed-feed-entries feed)))) + (json-encode + (mapcar #'elfeed-export-entry-to-alist 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