From 966bed8c8893980845f9b4c0cd8bb21481b1ec2a Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 30 Aug 2025 20:51:52 +1000 Subject: [emacs] Add my-ttrss --- emacs/.emacs.d/lisp/my/my-libgen.el | 30 +++++++------- emacs/.emacs.d/lisp/my/my-ttrss.el | 80 +++++++++++++++++++++++++++++++++++++ emacs/.emacs.d/lisp/my/my-utils.el | 3 ++ 3 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 emacs/.emacs.d/lisp/my/my-ttrss.el diff --git a/emacs/.emacs.d/lisp/my/my-libgen.el b/emacs/.emacs.d/lisp/my/my-libgen.el index 912f2df..a8e7dca 100644 --- a/emacs/.emacs.d/lisp/my/my-libgen.el +++ b/emacs/.emacs.d/lisp/my/my-libgen.el @@ -136,14 +136,13 @@ (alist-get 'coverurl info))))) (defun my-libgen-format-filename (info) - (replace-regexp-in-string "[:;?/]" "_" - (format - "%s - %s (%s) [%s].%s" - (alist-get 'author info) - (alist-get 'title info) - (alist-get 'year info) - (alist-get 'identifier info) - (alist-get 'extension info)))) + (my-make-doc-file-name (format + "%s - %s (%s) [%s].%s" + (alist-get 'author info) + (alist-get 'title info) + (alist-get 'year info) + (alist-get 'identifier info) + (alist-get 'extension info)))) (defvar my-libgen-download-dir "~/Downloads") @@ -509,14 +508,13 @@ (alist-get 'filesize-human info))) (defun my-libfic-format-filename (info) - (replace-regexp-in-string "[:;]" "_" - (format - "%s - %s (%s) [%s].%s" - (alist-get 'author info) - (alist-get 'title info) - (alist-get 'series info) - (alist-get 'identifier info) - (alist-get 'extension info)))) + (my-make-doc-file-name (format + "%s - %s (%s) [%s].%s" + (alist-get 'author info) + (alist-get 'title info) + (alist-get 'series info) + (alist-get 'identifier info) + (alist-get 'extension info)))) (defun my-grok-libfic-action (info) (interactive) 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 +;; 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 . + +;;; 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 "

" "" + (plist-get info :title) "" "

") + (insert "

" "" + (plist-get info :feed_title) "") + (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 "

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

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

"))) + (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 + diff --git a/emacs/.emacs.d/lisp/my/my-utils.el b/emacs/.emacs.d/lisp/my/my-utils.el index 98c8caa..550d33e 100644 --- a/emacs/.emacs.d/lisp/my/my-utils.el +++ b/emacs/.emacs.d/lisp/my/my-utils.el @@ -226,6 +226,9 @@ Example: (format-time-string ... (my-time-from-epoch 1698582504))" (replace-regexp-in-string "[[:punct:][:space:]\n\r]+" sep (string-trim name))) +(defun my-make-doc-file-name (name) + (replace-regexp-in-string "[:;?/]" "_" name)) + (defun my-make-filename-from-url (url) (let* ((urlobj (url-generic-parse-url url)) (filename (url-filename urlobj)) -- cgit v1.2.3