109 lines
5.3 KiB
EmacsLisp
109 lines
5.3 KiB
EmacsLisp
;; [[id:arroyo/feed-cache-tab-fragments][Code for tabular file =ggsrc= fragment generation:1]]
|
|
(defun arroyo-feeds-make-string (tbl)
|
|
"Converts an babelized org-mode tabel TBL in to an ggsrc command.
|
|
|
|
The table is three columns, NAME, FEED_URL, CATEGORY."
|
|
(->> tbl
|
|
(seq-map (lambda (line)
|
|
(format "rss \"%s\" %s # \"%s\"\n" (second line) (third line) (first line))))
|
|
(apply #'s-concat)))
|
|
;; Code for tabular file =ggsrc= fragment generation:1 ends here
|
|
|
|
;; [[id:arroyo/feed-cache-tab-fragments][Code for tabular file =ggsrc= fragment generation:2]]
|
|
(defun arroyo-feeds-write-file (ggsrc-block export-path)
|
|
(let* ((cce-directory (expand-file-name "cce" org-roam-directory))
|
|
(fname (expand-file-name export-path cce-directory)))
|
|
(with-current-buffer (find-file-noselect (expand-file-name export-path cce-directory))
|
|
(erase-buffer)
|
|
(insert ggsrc-block)
|
|
(save-buffer)
|
|
(format "[[%s][%s]]\n#+ARROYO_FEEDS: %s" fname export-path export-path))))
|
|
;; Code for tabular file =ggsrc= fragment generation:2 ends here
|
|
|
|
;; [[file:arroyo-feed-cache.org::*Code for Keyword Metadata =ggsrc= fragment generation][Code for Keyword Metadata =ggsrc= fragment generation:1]]
|
|
(defun arroyo-feeds--keyword-fragment ()
|
|
(->> (arroyo-db-get "ARROYO_FEED_URL")
|
|
;; add titles
|
|
(-map (pcase-lambda (`(,file ,url))
|
|
(let ((res (org-roam-db-query [:select title :from nodes
|
|
:where (= level 0) :and (= file $s1)]
|
|
file)))
|
|
(list file url (car (first res))))))
|
|
;; add feed category
|
|
(-map (pcase-lambda (`(,file ,url ,title))
|
|
(let ((res (arroyo-db-get "ARROYO_FEED_CATEGORY" file)))
|
|
(list file url title (first res)))))
|
|
;; format and output
|
|
(-map (pcase-lambda (`(,file ,url ,title ,category))
|
|
(concat "rss \"" url "\" " category
|
|
" # " (format "[[%s][%s]]" file title))))
|
|
(s-join "\n")))
|
|
;; Code for Keyword Metadata =ggsrc= fragment generation:1 ends here
|
|
|
|
;; [[id:arroyo/feed-cache-ggsrc][Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:1]]
|
|
(add-to-list 'arroyo-db-keywords "ARROYO_FEEDS")
|
|
(add-to-list 'arroyo-db-keywords "ARROYO_FEED_URL")
|
|
(add-to-list 'arroyo-db-keywords "ARROYO_FEED_CATEGORY")
|
|
;; Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:1 ends here
|
|
|
|
;; [[id:arroyo/feed-cache-ggsrc][Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:2]]
|
|
(defcustom arroyo-feeds-ggsrc-path "/ssh:fontkeming.fail:~/Maildir/ggsrc"
|
|
"The location to write final collated GGSRC file. This can be local or TRAMP path."
|
|
:group 'arroyo
|
|
:group 'arroyo-feeds
|
|
:type 'string)
|
|
|
|
(defun arroyo-feeds-flood (&optional no-restart)
|
|
"Create a ggsrc file suitable for the grey goo spawner. With prefix argument skip restarting service"
|
|
(interactive "P")
|
|
(with-current-buffer (find-file arroyo-feeds-ggsrc-path)
|
|
(erase-buffer)
|
|
(->> (arroyo-db-get "ARROYO_FEEDS")
|
|
(-sort #'arroyo-feeds--sort-pairs) ;;
|
|
(-map (pcase-lambda (`(,file ,dest))
|
|
(arroyo-feeds--call-file file) ;;
|
|
dest)) ;; done with file, return only dest
|
|
(append (list "ggs/0-rss-command.ggsrc"))
|
|
(arroyo-feeds--insert-files)) ;;
|
|
(goto-char (point-max))
|
|
(insert (arroyo-feeds--keyword-fragment)) ;;
|
|
(save-buffer))
|
|
|
|
(unless no-restart
|
|
(let ((default-directory "/ssh:fontkeming.fail:/home/rrix"))
|
|
(async-shell-command "sudo systemctl restart ua && echo \"done\""))))
|
|
;; Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:2 ends here
|
|
|
|
;; [[id:arroyo/feed-cache-ggsrc][Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:3]]
|
|
(defun arroyo-feeds--sort-pairs (one two)
|
|
(pcase-let ((`(,_ ,one-path) one)
|
|
(`(,_ ,two-path) two))
|
|
(s-less? one-path two-path)))
|
|
;; Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:3 ends here
|
|
|
|
;; [[id:arroyo/feed-cache-ggsrc][Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:4]]
|
|
(defun arroyo-feeds--ugly-execute-src-block (block-name)
|
|
(save-excursion
|
|
(goto-char (point-min))
|
|
(while (and (search-forward-regexp
|
|
(org-babel-named-src-block-regexp-for-name block-name)
|
|
nil t)
|
|
(org-babel-execute-src-block)))))
|
|
|
|
(defun arroyo-feeds--call-file (path)
|
|
(with-current-buffer (find-file-noselect path)
|
|
(arroyo-feeds--ugly-execute-src-block "tangle-file")))
|
|
;; Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:4 ends here
|
|
|
|
;; [[id:arroyo/feed-cache-ggsrc][Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:5]]
|
|
(defun arroyo-feeds--insert-files (files)
|
|
(let ((cce-directory (expand-file-name "cce" org-roam-directory)))
|
|
(dolist (fragment files)
|
|
(goto-char (point-max))
|
|
(insert-file-contents (expand-file-name fragment cce-directory)))))
|
|
;; Generating a =ggsrc= file for [[id:cce/universal_aggregator][Universal Aggregator]]:5 ends here
|
|
|
|
;; [[file:arroyo-feed-cache.org::*Footmatter][Footmatter:1]]
|
|
(provide 'arroyo-feeds)
|
|
;; Footmatter:1 ends here
|