2021-05-11 18:12:41 +02:00
|
|
|
#!/bin/sh
|
2021-06-12 18:27:40 +02:00
|
|
|
#gets called by newsboat if it finds a new article.
|
2021-05-11 18:12:41 +02:00
|
|
|
CACHE="${XDG_DATA_HOME:-$HOME/.local/share}/newsboat/cache.db"
|
2021-06-15 20:44:57 +02:00
|
|
|
CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls"
|
2021-05-12 00:08:52 +02:00
|
|
|
ALREADY_NOTIFIED="${XDG_DATA_HOME:-$HOME/.local/share}/newsboat/notified"
|
|
|
|
[ -f "$ALREADY_NOTIFIED" ] || touch "$ALREADY_NOTIFIED"
|
|
|
|
|
2021-06-15 20:44:57 +02:00
|
|
|
unread="$(sqlite3 "$CACHE" "SELECT unread,pubDate,title,feedurl FROM rss_item;" |
|
2021-05-12 00:08:52 +02:00
|
|
|
grep -vE '^0' | sort -t'|' -k2 -gr |
|
|
|
|
grep -vf "$ALREADY_NOTIFIED")"
|
2021-06-12 18:27:40 +02:00
|
|
|
[ -z "$unread" ] && exit
|
2021-05-12 00:08:52 +02:00
|
|
|
echo "$unread" >> "$ALREADY_NOTIFIED"
|
|
|
|
[ "$( echo "$unread" | wc -l)" -gt 1 ] && plural=s
|
2021-06-15 20:44:57 +02:00
|
|
|
articles="$(echo "$unread" | cut -d'|' -f3,4)"
|
|
|
|
output="$(echo "$articles" | while read -r article; do
|
|
|
|
#remove '?' queries from URL
|
|
|
|
title="$(echo "$article" | cut -d'|' -f1)"
|
|
|
|
feed="$(echo "$article" | cut -d'|' -f2 | sed 's/?.*//')"
|
|
|
|
#Find custom name given via name tag in CONFIG
|
|
|
|
name="$(grep "$feed" "$CONFIG" | grep '~' |
|
|
|
|
perl -pe "s/[^~\"]*\"~([^\"]*).*/\1/")"
|
|
|
|
#If no custom name present, use name from CACHE
|
|
|
|
if [ -z "$name" ]; then
|
|
|
|
name="$(sqlite3 "$CACHE" "SELECT url,title FROM rss_feed;" |
|
|
|
|
grep -F "$feed" | cut -d'|' -f2)"
|
|
|
|
fi
|
|
|
|
printf '%s:\n%s\n' "$name" "$title"
|
|
|
|
done)"
|
|
|
|
notify-send "new article${plural}" "$output"
|
2021-06-12 18:27:40 +02:00
|
|
|
|
|
|
|
#update statusbar to account for new articles
|
|
|
|
pkill -RTMIN+13 dwmblocks
|