diff options
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-ttrss.el')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-ttrss.el | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-ttrss.el b/emacs/.emacs.d/lisp/my/my-ttrss.el new file mode 100644 index 0000000..3695411 --- /dev/null +++ b/emacs/.emacs.d/lisp/my/my-ttrss.el @@ -0,0 +1,80 @@ +;;; my-ttrss.el -- ttrss utilities -*- lexical-binding: t -*- + +;; Copyright (C) 2025 Free Software Foundation, Inc. + +;; Author: Yuchen Pei <id@ypei.org> +;; Package-Requires: ((emacs "30.1")) + +;; This file is part of dotted. + +;; dotted is free software: you can redistribute it and/or modify it under +;; the terms of the GNU Affero General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; dotted is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +;; Public License for more details. + +;; You should have received a copy of the GNU Affero General Public +;; License along with dotted. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; ttrss utilities. + +;;; Code: + +(require 'ttrss) + +(defun my-ttrss-fetch (n) + "Fetch N articles." + (let ((ttrss-sid (ttrss-login ttrss-address ttrss-user ttrss-password))) + (if (ttrss-logged-in-p ttrss-address ttrss-sid) + (ttrss-get-headlines + ttrss-address ttrss-sid + :feed_id -4 :limit n :show_content t :include_attachments t) + (message "Login failed")))) + +(defun my-ttrss-save-article (info) + (with-temp-buffer + (insert "<h2>" "<a href=\"" (plist-get info :link) "\">" + (plist-get info :title) "</a>" "</h2>") + (insert "<p>" "<a href=\"" (plist-get info :site_url) "\">" + (plist-get info :feed_title) "</a>") + (when-let ((author (plist-get info :author))) + (unless (or (string-empty-p author) + (equal author (plist-get info :feed_title))) + (insert " (" author ")"))) + (insert " " + (format-time-string + "%Y-%m-%d %a %H:%M:%S" + (encode-time (decode-time (plist-get info :updated))))) + (insert "</p>") + (let ((tags (plist-get info :tags))) + (unless (seq-empty-p tags) + (insert "<p>tags: " (string-join tags ";") "</p>"))) + (insert (plist-get info :content)) + (let ((change-major-mode-with-file-name nil)) + (write-file (my-ttrss-format-file-name info))))) + +(defun my-ttrss-format-file-name (info) + "Format: $author - $title ($year) [ttrss$id].html" + (let ((author (plist-get info :author))) + (file-name-concat + my-webpage-incoming-dir + (my-make-doc-file-name + (format "%s - %s (%s) [ttrss%s].html" + (if (string-empty-p author) + (plist-get info :feed_title) + author) + (plist-get info :title) + (format-time-string + "%Y" + (encode-time (decode-time (plist-get info :updated)))) + (plist-get info :id)))))) + +(provide 'my-ttrss) +;;; my-ttrss.el ends here + |