summaryrefslogtreecommitdiff
path: root/README
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2022-02-26 12:29:39 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2022-02-26 12:34:23 +0100
commit8c0f231f734b5a9d736420eece311a87aa041103 (patch)
tree9e837e9991019097d26cc4e340ed04eaed5a788b /README
parentc1d2ebe8cac049808be400221c3ed4bda780cab7 (diff)
README: example scripts to count new and unread items
Diffstat (limited to 'README')
-rw-r--r--README52
1 files changed, 52 insertions, 0 deletions
diff --git a/README b/README
index 40037ab..398b96d 100644
--- a/README
+++ b/README
@@ -963,6 +963,58 @@ TSV format.
- - -
+Counting unread and total items
+-------------------------------
+
+It can be useful to show the counts of unread items, for example in a
+windowmanager or statusbar.
+
+The below example script counts the items of the last day in the same way the
+formatting tools do:
+
+ #!/bin/sh
+ # Count the new items of the last day.
+ LC_ALL=C awk -F '\t' -v "old=$(($(date +'%s') - 86400))" '
+ {
+ total++;
+ }
+ int($1) >= old {
+ totalnew++;
+ }
+ END {
+ print "New: " totalnew;
+ print "Total: " total;
+ }' ~/.sfeed/urls ~/.sfeed/feeds/*
+
+The below example script counts the unread items using the sfeed_curses URL
+file:
+
+ #!/bin/sh
+ # Count the unread and total items from feeds using the URL file.
+ LC_ALL=C awk -F '\t' '
+ # URL file: amount of fields is 1.
+ NF == 1 {
+ u[$0] = 1; # lookup table of URLs.
+ next;
+ }
+ # feed file: check by URL or id.
+ {
+ total++;
+ if (length($3)) {
+ if (u[$3])
+ read++;
+ } else if (length($6)) {
+ if (u[$6])
+ read++;
+ }
+ }
+ END {
+ print "Unread: " (total - read);
+ print "Total: " total;
+ }' ~/.sfeed/urls ~/.sfeed/feeds/*
+
+- - -
+
Running custom commands inside the program
------------------------------------------