aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2025-08-30 20:51:52 +1000
committerYuchen Pei <id@ypei.org>2025-08-30 20:51:52 +1000
commit966bed8c8893980845f9b4c0cd8bb21481b1ec2a (patch)
treeb420f0fd2938a8d5e25620c1159bef4a8339061e
parenta152ecc6ce54f67e93cd628b9105b6874d262f33 (diff)
[emacs] Add my-ttrss
-rw-r--r--emacs/.emacs.d/lisp/my/my-libgen.el30
-rw-r--r--emacs/.emacs.d/lisp/my/my-ttrss.el80
-rw-r--r--emacs/.emacs.d/lisp/my/my-utils.el3
3 files changed, 97 insertions, 16 deletions
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 <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
+
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))