Add CSV export
This commit is contained in:
parent
fbbe462de6
commit
fdcde7d425
3 changed files with 44 additions and 8 deletions
|
@ -11,8 +11,9 @@ The following export formats are currently supported:
|
||||||
|
|
||||||
| Format | Command |
|
| Format | Command |
|
||||||
|-------------------------+----------------------------|
|
|-------------------------+----------------------------|
|
||||||
| JSON | ~elfeed-export-to-json-file~ |
|
| CSV | ~elfeed-export-to-csv-file~ |
|
||||||
| Emacs Lisp Data (*.eld) | ~elfeed-export-to-lisp-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.
|
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.
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,34 @@ the entry should be exported."
|
||||||
"Return the Lisp data string for all entries that should be exported."
|
"Return the Lisp data string for all entries that should be exported."
|
||||||
(prin1-to-string (elfeed-export--entries)))
|
(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
|
;;;###autoload
|
||||||
(defun elfeed-export-to-json-file (path)
|
(defun elfeed-export-to-json-file (path)
|
||||||
"Write the JSON string to a file at PATH."
|
"Write the JSON string to a file at PATH."
|
||||||
|
@ -145,6 +173,12 @@ the entry should be exported."
|
||||||
(interactive "F")
|
(interactive "F")
|
||||||
(write-region (elfeed-export-to-lisp) nil path nil nil nil t))
|
(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)
|
(provide 'elfeed-export)
|
||||||
|
|
||||||
;;; elfeed-export.el ends here
|
;;; elfeed-export.el ends here
|
||||||
|
|
|
@ -39,8 +39,9 @@ Emacs (https://github.com/skeeto/elfeed).
|
||||||
|
|
||||||
Format Command
|
Format Command
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
JSON ‘elfeed-export-to-json-file’
|
CSV ‘elfeed-export-to-csv-file’
|
||||||
Emacs Lisp Data (*.eld) ‘elfeed-export-to-lisp-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
|
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,
|
a (more or less) readable copy of your database. For a real backup,
|
||||||
|
@ -162,12 +163,12 @@ configuration snippet:
|
||||||
Tag Table:
|
Tag Table:
|
||||||
Node: Top87
|
Node: Top87
|
||||||
Node: Introduction406
|
Node: Introduction406
|
||||||
Node: Installation1092
|
Node: Installation1150
|
||||||
Node: Configuration1497
|
Node: Configuration1555
|
||||||
Node: Customize export fields2231
|
Node: Customize export fields2289
|
||||||
Node: Customize entry filters3328
|
Node: Customize entry filters3386
|
||||||
Node: By tag3740
|
Node: By tag3798
|
||||||
Node: By feed4214
|
Node: By feed4272
|
||||||
|
|
||||||
End Tag Table
|
End Tag Table
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue