diff --git a/bin/derstandard b/bin/derstandard index 1346152..a8c836d 100755 --- a/bin/derstandard +++ b/bin/derstandard @@ -57,6 +57,15 @@ mark_seen() { fi } +prune_seen() { + # Keep only last 200 entries + local count=$(wc -l < "$SEEN_FILE" 2>/dev/null | tr -d ' ') + if [ "$count" -gt 200 ]; then + local excess=$((count - 200)) + tail -200 "$SEEN_FILE" > "${SEEN_FILE}.tmp" && mv "${SEEN_FILE}.tmp" "$SEEN_FILE" + fi +} + is_seen() { grep -qF "$1" "$SEEN_FILE" 2>/dev/null } @@ -74,16 +83,21 @@ case "${1:-}" in feed=$(fetch_feed "$max") - # Build items list + # Build items list, mark all as seen, only display unseen (unless --all) while IFS=$'\t' read -r title url; do if $show_all || ! is_seen "$url"; then printf '%s\t%s\n' "$title" "$url" fi + # Mark as seen regardless of display + mark_seen "$url" done < <( titles=$(echo "$feed" | grep -oP '\K[^<]+' | tail -n +2 | decode_entities) urls=$(echo "$feed" | grep -oP '<link>\K[^<]+' | grep "derstandard.at/story") paste <(echo "$titles") <(echo "$urls") 2>/dev/null | head -"$max" ) + + # Prune to max 200 entries + prune_seen ;; article) [ -z "${2:-}" ] && { echo "Usage: derstandard article <url>"; exit 1; } @@ -102,6 +116,7 @@ case "${1:-}" in # Mark as seen mark_seen "$url" done + prune_seen ;; urls) fetch_feed "${2:-50}" | grep -oP '<link>\K[^<]+' | grep "derstandard.at/story" diff --git a/memory/derstandard-seen.txt b/memory/derstandard-seen.txt index b873fe8..10437cc 100644 --- a/memory/derstandard-seen.txt +++ b/memory/derstandard-seen.txt @@ -1 +1,5 @@ +https://www.derstandard.at/story/3000000306979/trump-always-chickens-out-macht-taco-tatsaechlich-immer-einen-rueckzieher?ref=rss https://www.derstandard.at/story/3000000307063/usa-schiessen-iranische-drohne-nahe-flugzeugtraeger-im-arabischen-meer-ab?ref=rss +https://www.derstandard.at/story/3000000306672/neue-epstein-files-werfen-fragen-an-adelige-diplomaten-und-eva-dichand-auf?ref=rss +https://www.derstandard.at/story/3000000306965/wodurch-fast-vier-von-zehn-krebsfaellen-vermeidbar-waeren?ref=rss +https://www.derstandard.at/story/3000000306903/etappensieg-fuer-saudischen-staatsfonds-mubadala-im-streit-mit-signa?ref=rss