1
0
Fork 0

Add CSV export

This commit is contained in:
Bram Schoenmakers 2024-08-06 06:12:12 +02:00
parent fbbe462de6
commit fdcde7d425
Signed by: bram
GPG key ID: 0CCD19DFDC63258F
3 changed files with 44 additions and 8 deletions

View file

@ -11,8 +11,9 @@ The following export formats are currently supported:
| Format | Command |
|-------------------------+----------------------------|
| JSON | ~elfeed-export-to-json-file~ |
| CSV | ~elfeed-export-to-csv-file~ |
| Emacs Lisp Data (*.eld) | ~elfeed-export-to-lisp-file~ |
| JSON | ~elfeed-export-to-json-file~ |
Please note there is *no import functionality*. The goal is to have a (more or less) readable copy of your database. For a real backup, make a backup of ~/.elfeed instead.

View file

@ -133,6 +133,34 @@ the entry should be exported."
"Return the Lisp data string for all entries that should be exported."
(prin1-to-string (elfeed-export--entries)))
(defun elfeed-export--format-csv-value (value)
(let* ((string-value (if (listp value)
(format "[%s]"
(mapconcat (lambda (elm)
(format "%s" elm))
value ";"))
(format "%s" value)))
(escaped-string (string-replace "\"" "\"\"" string-value)))
(format "\"%s\"" escaped-string)))
;;;###autoload
(defun elfeed-export-to-csv ()
"Return the CSV string for all entries that should be exported."
(let* ((entries (elfeed-export--entries))
(columns (map-keys (seq-first entries))))
(concat
;; header
(string-join columns ",")
"\n"
;; data
(mapconcat (lambda (entry)
(mapconcat (lambda (column)
(elfeed-export--format-csv-value (alist-get column entry)))
columns
","))
entries
"\n"))))
;;;###autoload
(defun elfeed-export-to-json-file (path)
"Write the JSON string to a file at PATH."
@ -145,6 +173,12 @@ the entry should be exported."
(interactive "F")
(write-region (elfeed-export-to-lisp) nil path nil nil nil t))
;;;###autoload
(defun elfeed-export-to-csv-file (path)
"Write the CSV string to a file at PATH."
(interactive "F")
(write-region (elfeed-export-to-csv) nil path nil nil nil t))
(provide 'elfeed-export)
;;; elfeed-export.el ends here

View file

@ -39,8 +39,9 @@ Emacs (https://github.com/skeeto/elfeed).
Format Command
---------------------------------------------------------
JSON elfeed-export-to-json-file
CSV elfeed-export-to-csv-file
Emacs Lisp Data (*.eld) elfeed-export-to-lisp-file
JSON elfeed-export-to-json-file
Please note there is *no import functionality*. The goal is to have
a (more or less) readable copy of your database. For a real backup,
@ -162,12 +163,12 @@ configuration snippet:
Tag Table:
Node: Top87
Node: Introduction406
Node: Installation1092
Node: Configuration1497
Node: Customize export fields2231
Node: Customize entry filters3328
Node: By tag3740
Node: By feed4214
Node: Installation1150
Node: Configuration1555
Node: Customize export fields2289
Node: Customize entry filters3386
Node: By tag3798
Node: By feed4272

End Tag Table