summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-12-30 18:16:31 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2021-12-30 18:21:36 +0100
commit74bd49c1e529a31d8fd4fa78bcbcac6e2b852f74 (patch)
treef6492b4eb4143789e13169c3db895417b5bb8493
downloadrss_filter-74bd49c1e529a31d8fd4fa78bcbcac6e2b852f74.tar.gz
rss_filter-74bd49c1e529a31d8fd4fa78bcbcac6e2b852f74.tar.xz
Add rss-filter.
-rw-r--r--files/config.scm52
-rw-r--r--files/rss-filter.service7
-rw-r--r--files/rss-filter.timer5
-rw-r--r--manifests/init.pp32
4 files changed, 96 insertions, 0 deletions
diff --git a/files/config.scm b/files/config.scm
new file mode 100644
index 0000000..9b20bcf
--- /dev/null
+++ b/files/config.scm
@@ -0,0 +1,52 @@
+(define-module (config)
+ :export (feeds))
+
+(use-modules
+ (sxml xpath)
+ (ice-9 regex)
+
+ (rss-filter feed-handler)
+
+ ((ice-9 i18n) :select (make-locale))
+ ((texinfo string-utils) :select (escape-special-chars))
+
+ ((calp util) :select (->))
+ ((datetime) :select (datetime datetime->string
+ string->datetime)))
+
+
+(define feeds
+ (list
+ (make-feed
+ "https://lwn.net/headlines/Features"
+ `((rss:item
+ . ,(lambda (key . children)
+ (define tag (cons key children))
+ (call-with-values (lambda () (apply values ((sxpath '(rss:title *text*)) tag)))
+ (case-lambda (() tag)
+ ((title . _)
+ (if (string-match (escape-special-chars "^[$]" "[]$" #\\)
+ title)
+ '() tag))))))))
+
+ (make-feed
+ "https://swordscomic.com/comic/feed/"
+ `((rss:pubDate
+ . ,(lambda (key . children)
+ (list key
+ (-> (car children)
+ (string->datetime "~b. ~d, ~Y, ~H:~M ~p" (make-locale LC_TIME "en_US.UTF-8"))
+ (datetime->string "~Y-~m-~dT~H:~M:~S")))))
+
+ (rss:description
+ . ,(lambda (key . children)
+ (cons key
+ ;; Each entry has a <style/> tag at the
+ ;; beggining, which brakes the short preview on
+ ;; NetNewsWire. This removes it
+ (cond ((string-match "</style>" (car children))
+ => (lambda (m)
+ (list (string-drop (car children) (match:end m)))))
+ (else children)))))
+ ))
+ ))
diff --git a/files/rss-filter.service b/files/rss-filter.service
new file mode 100644
index 0000000..541da3d
--- /dev/null
+++ b/files/rss-filter.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Fetch and filter RSS feeds
+
+[Service]
+EnvironmentFile=/etc/rss-filter/environment
+ExecStart=/usr/bin/rss-filter --output $OUTDIR --config-dir /etc/rss-filter
+Type=oneshot
diff --git a/files/rss-filter.timer b/files/rss-filter.timer
new file mode 100644
index 0000000..a793107
--- /dev/null
+++ b/files/rss-filter.timer
@@ -0,0 +1,5 @@
+[Timer]
+OnCalendar=*:0/30
+
+[Install]
+WantedBy=default.target
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..2663dea
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,32 @@
+class rss_filter {
+
+ # Once I get it into the repos
+ # ensure_packages(['rss-filter'])
+
+ systemd::unit_file { 'rss-filter.service':
+ source => "puppet:///modules/${module_name}/rss-filter.service",
+ }
+
+ systemd::unit_file { 'rss-filter.timer':
+ source => "puppet:///modules/${module_name}/rss-filter.timer",
+ }
+
+ file { '/etc/rss-filter':
+ ensure => directory,
+ }
+
+ file { '/etc/rss-filter/environment':
+ ensure => file,
+ content => "OUTDIR=/var/www/adrift.space/rss\n",
+ }
+
+ file { '/etc/rss-filter/config.scm':
+ ensure => file,
+ source => "puppet:///modules/${module_name}/config.scm",
+ }
+
+ service { 'rss-filter.timer':
+ ensure => running,
+ enable => true,
+ }
+}