From bc299eac5c1e4f4463e09c892ba4e3b09f82a9c1 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sun, 31 Aug 2025 20:58:25 +1000 Subject: [emacs] my-ttrss sets mtime of articles Also added a standalone script to call the fetch function --- emacs/.emacs.d/lisp/my/my-ttrss.el | 66 +++++++++++++++++++++----------------- emacs/.emacs.d/lisp/my/my-utils.el | 3 ++ emacs/.emacs.d/lisp/ttrss.el | 2 +- misc/bin/ttrss-fetch.el | 10 ++++++ 4 files changed, 51 insertions(+), 30 deletions(-) create mode 100755 misc/bin/ttrss-fetch.el diff --git a/emacs/.emacs.d/lisp/my/my-ttrss.el b/emacs/.emacs.d/lisp/my/my-ttrss.el index 3cf6856..046f596 100644 --- a/emacs/.emacs.d/lisp/my/my-ttrss.el +++ b/emacs/.emacs.d/lisp/my/my-ttrss.el @@ -27,6 +27,8 @@ ;;; Code: (require 'ttrss) +(require 'my-utils) +(require 'org-macs) ;;; TODO: my-ttrss-save-recent @@ -94,10 +96,15 @@ (ttrss-get-headlines ttrss-address sid :feed_id (plist-get feed :id) :show_content t :include_attachments t - :since_id (my-ttrss-feed-last-id feed)))) + :since_id (my-ttrss-feed-get-last-id feed)))) (seq-do 'my-ttrss-save-article articles) (unless (seq-empty-p articles) - (my-ttrss-feed-write-last-id feed (plist-get (elt articles 0) :id))) + (my-ttrss-feed-write-last-id + feed + (seq-reduce + (lambda (acc article) (max acc (plist-get article :id))) + articles + 0))) (message "%s Done - total %d articles" message-head (length articles)))) @@ -127,33 +134,34 @@ (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 "

") - (let ((tags (plist-get info :tags))) - (unless (seq-empty-p tags) - (insert "

tags: " (string-join tags ";") "

"))) - (insert (plist-get info :content)) - (let ((attached (plist-get info :attachments))) - (unless (seq-empty-p attached) - (insert "

Article attachments:

\n"))) - (let* ((change-major-mode-with-file-name nil) - (coding-system-for-write 'utf-8) - (inhibit-message t) - (file-name (my-ttrss-format-file-name info)) - (dir (file-name-directory file-name))) - (unless (file-exists-p dir) (make-directory dir t)) - (write-file file-name)))) + (let ((updated (format-time-string + "%Y-%m-%d %a %H:%M:%S" + (encode-time (decode-time (plist-get info :updated)))))) + (insert " " updated) + (insert "

") + (let ((tags (plist-get info :tags))) + (unless (seq-empty-p tags) + (insert "

tags: " (string-join tags ";") "

"))) + (insert (plist-get info :content)) + (let ((attached (plist-get info :attachments))) + (unless (seq-empty-p attached) + (insert "

Article attachments:

\n"))) + (let* ((change-major-mode-with-file-name nil) + (coding-system-for-write 'utf-8) + (inhibit-message t) + (file-name (my-ttrss-format-file-name info)) + (dir (file-name-directory file-name))) + (unless (file-exists-p dir) (make-directory dir t)) + (write-file file-name) + (my-touch-file-mtime file-name updated))))) (defvar my-ttrss-dir "~/Downloads") diff --git a/emacs/.emacs.d/lisp/my/my-utils.el b/emacs/.emacs.d/lisp/my/my-utils.el index 550d33e..05ca2e6 100644 --- a/emacs/.emacs.d/lisp/my/my-utils.el +++ b/emacs/.emacs.d/lisp/my/my-utils.el @@ -319,6 +319,9 @@ Example: (format-time-string ... (my-time-from-epoch 1698582504))" "Touch a new file." (with-temp-buffer (write-file filename))) +(defun my-touch-file-mtime (file date) + (call-process "touch" nil nil nil "-d" date file)) + (defvar my-extension-types '((audio . ("asf" "cue" "flac" "m4a" "m4r" "mid" "mp3" "ogg" "opus" "wav" "wma" "spc" "mp4")) diff --git a/emacs/.emacs.d/lisp/ttrss.el b/emacs/.emacs.d/lisp/ttrss.el index 6dfa980..d9d51f8 160000 --- a/emacs/.emacs.d/lisp/ttrss.el +++ b/emacs/.emacs.d/lisp/ttrss.el @@ -1 +1 @@ -Subproject commit 6dfa980bf4ed1762108bf2ffc4e9e0b680263cc5 +Subproject commit d9d51f823cbb5bcd45a59e0fb578a13fa8d60034 diff --git a/misc/bin/ttrss-fetch.el b/misc/bin/ttrss-fetch.el new file mode 100755 index 0000000..770ff46 --- /dev/null +++ b/misc/bin/ttrss-fetch.el @@ -0,0 +1,10 @@ +#!/bin/emacs --script + +(add-to-list 'load-path (locate-user-emacs-file "lisp/ttrss.el")) +(add-to-list 'load-path (locate-user-emacs-file "lisp/my")) +(require 'my-ttrss) +(require 'my-package) +(my-read-local-config) +(my-setq-from-local ttrss-address ttrss-user ttrss-password) +(my-setq-from-local my-ttrss-dir) +(my-ttrss-fetch) -- cgit v1.2.3