commit 0fc05d4c99b46499d875918dff70f193d72e6511
parent b8cbe5fa5140edb398f87f6c0eaf3e4cabf059e1
Author: Yuval Langer <yuval.langer@gmail.com>
Date: Sat, 4 Nov 2023 19:17:57 +0200
Use read-symbol-shorthands, try dash.el threading, and sanitise URL, maybe.
Diffstat:
M | elfeed-nitter.el | | | 119 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
1 file changed, 81 insertions(+), 38 deletions(-)
diff --git a/elfeed-nitter.el b/elfeed-nitter.el
@@ -1,41 +1,74 @@
-;;; SPDX-FileCopyrightText: 2023 Yuval Langer <yuval.langer@gmail.com>
-;;;
-;;; SPDX-License-Identifier: GPL-3.0-or-later
+;;; elfeed-nitter.el --- Download Nitter RSS feeds from random instances. -*- lexical-binding: t; -*-
-(defcustom elfeed-nitter-tags
+;; SPDX-FileCopyrightText: 2023 Yuval Langer <yuval.langer@gmail.com>
+;;
+;; SPDX-License-Identifier: GPL-3.0-or-later
+
+;; Copyright (C) 2023 Yuval Langer
+
+;; Author: Yuval Langer <yuval.langer@gmail.com>
+;; Version: 0.0.0
+;; Keywords:
+;; URL: https://kaka.farm/stagit/elfeed-nitter/log.html
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program 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 General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Usage:
+;;
+;; None yet.
+
+;;; Code:
+
+(require 'dash)
+(require 'cl-lib)
+
+(defcustom en-tags
'(elfeed-nitter)
"Tags added by default to the elfeed-nitter entries.")
-(defcustom elfeed-nitter-domains
+(defcustom en-domains
'("nitter.net")
"Nitter instance domains used in making the elfeed-nitter entries.")
-(defcustom elfeed-nitter-paths
+(defcustom en-paths
'(("emacs/rss" without_replies)
("emacs/with_replies/rss" with_replies))
"Wanted Nitter feeds.")
-(defcustom elfeed-nitter-wiki-url
+(defcustom en-wiki-url
"https://github.com/zedeus/nitter.wiki.git"
"The URL of the wiki. For git clone-ing purposes.")
-(defvar elfeed-nitter-path
+(defvar en-path
(locate-user-emacs-file "elfeed-nitter/"))
-(defvar elfeed-nitter-wiki-path
- (concat elfeed-nitter-path
+(defvar en-wiki-path
+ (concat en-path
"nitter-wiki/"))
-(defvar elfeed-nitter-instances-list-path
- (concat elfeed-nitter-path
+(defvar en-instances-list-path
+ (concat en-path
"nitter-wiki/Instances.md"))
-(defun elfeed-nitter-make-random-feeds-alist ()
+(defun en-make-random-feeds-alist ()
(cl-loop
- for entry in elfeed-nitter-paths
+ for entry in en-paths
collect
- (let* ((nitter-domain (nth (random (length elfeed-nitter-domains))
- elfeed-nitter-domains))
+ (let* ((nitter-domain (nth (random (length en-domains))
+ en-domains))
(url (concat "https://"
nitter-domain
"/"
@@ -46,16 +79,16 @@
(rest-of-the-tags (cdr entry)))
(append (list url
nitter-domain-tag)
- elfeed-nitter-tags
+ en-tags
rest-of-the-tags))))
-(defun elfeed-nitter-make-feeds-alist ()
+(defun en-make-feeds-alist ()
(apply 'append
(cl-loop
- for nitter-domain in elfeed-nitter-domains
+ for nitter-domain in en-domains
collect
(cl-loop
- for entry in elfeed-nitter-paths
+ for entry in en-paths
collect
(let ((url (concat "https://"
nitter-domain
@@ -67,32 +100,32 @@
(rest-of-the-tags (cdr entry)))
(append (list url
nitter-domain-tag)
- elfeed-nitter-tags
+ en-tags
rest-of-the-tags))))))
-(defun elfeed-nitter-update-random-instances ()
- (let* ((elfeed-feeds (elfeed-nitter-make-random-feeds-alist)))
+(defun en-update-random-instances ()
+ (let* ((elfeed-feeds (en-make-random-feeds-alist)))
(elfeed-update)))
-(defun elfeed-nitter--clone-nitter-wiki ()
+(defun en--clone-nitter-wiki ()
(ignore-error 'file-already-exists
- (make-directory elfeed-nitter-path))
+ (make-directory en-path))
(shell-command-to-string (format "git clone %s %s"
- elfeed-nitter-wiki-url
- elfeed-nitter-wiki-path)))
+ en-wiki-url
+ en-wiki-path)))
-(defun elfeed-nitter--update-nitter-wiki ()
+(defun en--update-nitter-wiki ()
(ignore-error 'file-already-exists
- (make-directory elfeed-nitter-path))
- (let ((default-directory elfeed-nitter-wiki-path))
+ (make-directory en-path))
+ (let ((default-directory en-wiki-path))
(shell-command-to-string (format "git pull --ff-only %s"
- elfeed-nitter-wiki-url))))
+ en-wiki-url))))
-(defun elfeed-nitter-make-instances-hosts-list ()
+(defun en-make-instances-hosts-list ()
(cl-loop
with instances-file-contents =
(with-temp-buffer
- (insert-file-contents elfeed-nitter-instances-list-path)
+ (insert-file-contents en-instances-list-path)
(buffer-string))
with lines =
@@ -110,8 +143,18 @@
line)
collect
- (let* ((uri-string (replace-regexp-in-string
- "|\s*\\[.*\\](\\(.*\\)).*white_check_mark:\s*|\s*:white_check_mark.*" "\\1"
- line))
- (uri-object (url-generic-parse-url uri-string)))
- (url-host uri-object))))
+ (->> line
+ (replace-regexp-in-string
+ "|\s*\\[.*\\](\\(.*\\)).*white_check_mark:\s*|\s*:white_check_mark.*" "\\1")
+ url-generic-parse-url
+ url-host
+ ;; XXX: Will this sanitise the URL thingimajig?
+ url-hexify-string
+ )))
+
+(provide 'elfeed-nitter)
+
+;; Local Variables:
+;; read-symbol-shorthands: (("en-" . "elfeed-nitter-"))
+;; End:
+;;; elfeed-nitter.el ends here