blob: 7987f0ba6183bb1b10531acfcf18d3bc4d04c12a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#!/bin/sh
# Set as a cron job to check for new RSS entries for newsboat.
# If newsboat is open, sends it an "R" key to refresh.
# Bail if a previous run is still going. With the fulltext filter a reload now
# takes ~17s+, so back-to-back cron ticks could overlap: a second `-x reload`
# can't grab the cache.db lock, and the rm/signal races blank the status bar.
exec 9>/tmp/newsup.lock
flock -n 9 || exit
/usr/bin/notify-send "📰 Updating RSS feeds..."
pgrep -x newsboat && /usr/bin/xdotool key --window "$(/usr/bin/xdotool search --name "^newsboat$")" R && exit
echo "📰$(/usr/bin/newsboat -x print-unread | awk '{print $1}')🔃" >/tmp/newsupdate
pkill -RTMIN+14 "${STATUSBAR:-dwmblocks}"
/usr/bin/newsboat -x reload
# Prune feeds no longer in the urls file. Editing urls directly (removing or
# changing a feed) leaves the old feed's items in cache.db; newsboat hides them
# (not in urls) but sb-news counts every unread row, so they show as a phantom
# count. cleanup-on-quit only fires on a graceful `q` quit, so we replicate it
# here non-interactively: any rss_feed.rssurl not present in urls is an orphan.
# Safe to write directly — newsboat isn't running in this branch (it exits at
# the xdotool line above) and `-x reload` has already released the cache lock.
nb_db="${XDG_DATA_HOME:-${HOME}/.local/share}/newsboat/cache.db"
nb_urls="${XDG_CONFIG_HOME:-${HOME}/.config}/newsboat/urls"
awk '!/^[[:space:]]*#/ && ($1 ~ /^https?:/ || $1 ~ /^filter:/){print $1}' "$nb_urls" \
| sort -u >/tmp/newsup_urls.$$
/usr/bin/sqlite3 "$nb_db" "SELECT rssurl FROM rss_feed;" | sort -u \
| comm -23 - /tmp/newsup_urls.$$ | while IFS= read -r u; do
[ -n "$u" ] && /usr/bin/sqlite3 "$nb_db" \
"DELETE FROM rss_item WHERE feedurl='$u'; DELETE FROM rss_feed WHERE rssurl='$u';"
done
rm -f /tmp/newsup_urls.$$
rm -f /tmp/newsupdate
pkill -RTMIN+14 "${STATUSBAR:-dwmblocks}"
/usr/bin/notify-send "📰 RSS feed update complete."
|