scripts

Various scripts for UNIX-like systems
git clone https://git.tronto.net/scripts
Download | Log | Files | Refs | README

commit 06931dfdb443584a2c140bf53a12cff9dc239557
parent 026bcfc65687ba14299ea2f553940f62388874ce
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun,  2 Jul 2023 13:36:02 +0200

New feed manager

Diffstat:
MMakefile | 1+
Afeed | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsfeed-browser -> old/sfeed-browser | 0
3 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -14,6 +14,7 @@ SCRIPTS = addressgrep \ dmenu-unmount \ dmenu-urlselect \ dmenu-websearch \ + feed \ ffmpeg-screenrecord \ ffmpeg-facecam \ mail-compose \ diff --git a/feed b/feed @@ -0,0 +1,83 @@ +#!/bin/sh + +# RSS feed manager + +# Requires: sfeed, sfeed_plain (get), dmenu, open-url (menu) + +# Usage: feed [-m menu] [get|menu|clear|edit] + +dir=$HOME/box/sfeed +feeddir=$dir/urls +destdir=$dir/new +olddir=$dir/old +readdir=$dir/last +menu="dmenu -l 20 -i" +urlopener=open-url + +usage() { + echo "Usage: feed [get|menu|clear|show]" +} + +getnew() { + for f in "$feeddir"/*; do + read -r url < "$f" + name=$(basename "$f") + d="$destdir/$name" + r="$readdir/$name" + + [ -f "$r" ] && read -r lr < "$r" || lr=0 + + # Get new feed items + tmp=$(mktemp) + curl -s "$url" | sfeed | \ + awk -v lr="$lr" '$1 > lr {print $0}' | \ + tee "$tmp" | sfeed_plain >> "$d" + + # Update last time stamp + awk -v lr="$lr" '$1 > lr {lr=$1} END {print lr}' <"$tmp" >"$r" + done +} + +showmenu() { + cat "$destdir"/* | $menu | awk '{print $NF}' | xargs $urlopener +} + +while getopts "m:" opt; do + case "$opt" in + m) + menu="$OPTARG" + ;; + *) + usage + exit 1 + ;; + esac +done + +shift $((OPTIND - 1)) + +if [ -z "$1" ]; then + usage + exit 1 +fi + +case "$1" in + get) + getnew + ;; + menu) + showmenu + ;; + clear) + d="$olddir/$(date +'%Y-%m-%d-%H-%M-%S')" + mkdir "$d" + mv "$destdir"/* "$d/" + ;; + show) + cat "$destdir"/* + ;; + *) + usage + exit 1 + ;; +esac diff --git a/sfeed-browser b/old/sfeed-browser