commit 25647d73c6dc1c8ff6d0095a392fa77a807c91e3 Author: Yuval Langer <yuval.langer@gmail.com> Date: Fri, 3 Nov 2023 16:57:01 +0200 First commit. Diffstat:
A | README.org | | | 8 | ++++++++ |
A | elfeed-nitter.el | | | 105 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 113 insertions(+), 0 deletions(-)
diff --git a/README.org b/README.org @@ -0,0 +1,8 @@ +# SPDX-FileCopyrightText: 2023 Yuval Langer <yuval.langer@gmail.com> +# +# SPDX-License-Identifier: GPL-3.0-or-later + +#+title: Elfeed Nitter + +Download Nitter RSS feeds in such a way that for each feed it will +choose a random nitter instance. diff --git a/elfeed-nitter.el b/elfeed-nitter.el @@ -0,0 +1,105 @@ +;;; SPDX-FileCopyrightText: 2023 Yuval Langer <yuval.langer@gmail.com> +;;; +;;; SPDX-License-Identifier: GPL-3.0-or-later + +(defcustom elfeed-nitter-tags + '(elfeed-nitter) + "Tags added by default to the elfeed-nitter entries.") + +(defcustom elfeed-nitter-domains + '("nitter.net") + "Nitter instance domains used in making the elfeed-nitter entries.") + +(defcustom elfeed-nitter-paths + '(("emacs/rss" without_replies) + ("emacs/with_replies/rss" with_replies)) + "Wanted Nitter feeds.") + +(defcustom elfeed-nitter-wiki-url + "https://github.com/zedeus/nitter.wiki.git" + "The URL of the wiki. For git clone-ing purposes.") + +(defun elfeed-nitter-make-random-feeds-alist () + (cl-loop + for entry in elfeed-nitter-paths + collect + (let* ((nitter-domain (nth (random (length elfeed-nitter-domains)) + elfeed-nitter-domains)) + (url (concat "https://" + nitter-domain + "/" + (car entry))) + (nitter-domain-tag (intern (string-replace "." + "-" + nitter-domain))) + (rest-of-the-tags (cdr entry))) + (append (list url + nitter-domain-tag) + elfeed-nitter-tags + rest-of-the-tags)))) + +(defun elfeed-nitter-make-feeds-alist () + (apply 'append + (cl-loop + for nitter-domain in elfeed-nitter-domains + collect + (cl-loop + for entry in elfeed-nitter-paths + collect + (let ((url (concat "https://" + nitter-domain + "/" + (car entry))) + (nitter-domain-tag (intern (string-replace "." + "-" + nitter-domain))) + (rest-of-the-tags (cdr entry))) + (append (list url + nitter-domain-tag) + elfeed-nitter-tags + rest-of-the-tags)))))) + +(defun elfeed-nitter-update-random-instances () + (let ((elfeed-feeds elfeed-feeds)) + (setq elfeed-feeds + (append elfeed-feeds + (elfeed-nitter-make-random-feeds-alist))) + (elfeed-update))) + +(defun elfeed-nitter--clone-nitter-wiki () + (let* ((elfeed-nitter-path (locate-user-emacs-file "elfeed-nitter/")) + (nitter-wiki-path (concat elfeed-nitter-path + "nitter-wiki/"))) + (ignore-error 'file-already-exists + (make-directory elfeed-nitter-path)) + (shell-command-to-string (concat "git clone https://github.com/zedeus/nitter.wiki.git " + nitter-wiki-path)))) + +(defun elfeed-nitter--update-nitter-wiki () + (let* ((elfeed-nitter-path (locate-user-emacs-file "elfeed-nitter/")) + (nitter-wiki-path (concat elfeed-nitter-path + "nitter-wiki/"))) + (ignore-error 'file-already-exists + (make-directory elfeed-nitter-path)) + (let ((default-directory nitter-wiki-path)) + (shell-command-to-string (format "git pull --ff-only %s" + "https://github.com/zedeus/nitter.wiki.git"))))) + +(defun elfeed-nitter-make-instances-list () + (let* ((elfeed-nitter-path (locate-user-emacs-file "elfeed-nitter/")) + (nitter-wiki-path (concat elfeed-nitter-path + "nitter-wiki/Instances.md")) + (instances-file-contents (with-temp-buffer + (insert-file-contents nitter-wiki-path) + (buffer-string))) + (lines (string-split instances-file-contents + "\n"))) + (cl-loop + for line in lines + when (string-match "white_check_mark:\s*|\s*:white_check_mark" + line) + unless (string-match "auth required" + line) + collect + (replace-regexp-in-string "|\s*\\[.*\\](\\(.*\\)).*white_check_mark:\s*|\s*:white_check_mark.*" "\\1" + line))))