aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/my-ttrss.el
blob: 36954112f843417aa02a2720dddc05cd30295d3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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