aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2025-08-31 20:58:25 +1000
committerYuchen Pei <id@ypei.org>2025-08-31 20:58:25 +1000
commitbc299eac5c1e4f4463e09c892ba4e3b09f82a9c1 (patch)
tree23a613115cee0876d4a6a256f17f9e6653826629
parent2e90e2e3b9d6f67e40b7cd52705ffba4632a2962 (diff)
[emacs] my-ttrss sets mtime of articles
Also added a standalone script to call the fetch function
-rw-r--r--emacs/.emacs.d/lisp/my/my-ttrss.el66
-rw-r--r--emacs/.emacs.d/lisp/my/my-utils.el3
m---------emacs/.emacs.d/lisp/ttrss.el0
-rwxr-xr-xmisc/bin/ttrss-fetch.el10
4 files changed, 50 insertions, 29 deletions
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 "</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 ((attached (plist-get info :attachments)))
- (unless (seq-empty-p attached)
- (insert "<p>Article attachments:</p>\n<ul>")
- (seq-do (lambda (at)
- (let ((title (plist-get at :title))
- (url (plist-get at :content_url)))
- (insert "\n<li><a href=" url ">"
- (if (string-empty-p title) url title)
- "</a></li>")))
- attached)
- (insert "\n</ul>")))
- (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 "</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 ((attached (plist-get info :attachments)))
+ (unless (seq-empty-p attached)
+ (insert "<p>Article attachments:</p>\n<ul>")
+ (seq-do (lambda (at)
+ (let ((title (plist-get at :title))
+ (url (plist-get at :content_url)))
+ (insert "\n<li><a href=" url ">"
+ (if (string-empty-p title) url title)
+ "</a></li>")))
+ attached)
+ (insert "\n</ul>")))
+ (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
-Subproject 6dfa980bf4ed1762108bf2ffc4e9e0b680263cc
+Subproject d9d51f823cbb5bcd45a59e0fb578a13fa8d6003
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)