79 lines
2.4 KiB
Bash
Executable file
79 lines
2.4 KiB
Bash
Executable file
#!/bin/bash
|
|
# Der Standard RSS helper - fetches via internal fivefilters
|
|
set -e
|
|
|
|
FIVEFILTERS_URL="https://fivefilters.cloonar.com"
|
|
RSS_SOURCE="https://www.derstandard.at/rss"
|
|
|
|
CURL="curl -sk"
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: derstandard <command> [args]
|
|
|
|
Commands:
|
|
items [max] Title + URL pairs for selection (default: 50)
|
|
article <url> Fetch single article content
|
|
articles <url1,url2,...> Fetch multiple articles (comma-separated)
|
|
urls [max] Article URLs only
|
|
titles [max] Article titles only
|
|
raw [max] Full RSS XML
|
|
EOF
|
|
}
|
|
|
|
fetch_feed() {
|
|
local max="${1:-50}"
|
|
local encoded_url=$(printf '%s' "$RSS_SOURCE" | sed 's/:/%3A/g; s/\//%2F/g')
|
|
$CURL "${FIVEFILTERS_URL}/makefulltextfeed.php?url=${encoded_url}&max=${max}&links=preserve&exc="
|
|
}
|
|
|
|
fetch_single_article() {
|
|
local url="$1"
|
|
local encoded_url=$(printf '%s' "$url" | sed 's/:/%3A/g; s/\//%2F/g; s/\?/%3F/g; s/&/%26/g; s/=/%3D/g')
|
|
$CURL "${FIVEFILTERS_URL}/makefulltextfeed.php?url=${encoded_url}&max=1&links=preserve&exc=" | \
|
|
perl -0777 -ne 'print $1 if /<item>.*?<description>(.*?)<\/description>.*?<\/item>/s' | \
|
|
sed 's/</</g; s/>/>/g; s/"/"/g; s/&/\&/g' | \
|
|
sed 's/<[^>]*>//g' | \
|
|
tr '\n' ' ' | sed 's/ */ /g'
|
|
}
|
|
|
|
decode_entities() {
|
|
sed 's/&amp;/\&/g; s/&/\&/g; s/</</g; s/>/>/g; s/"/"/g; s/'/'"'"'/g'
|
|
}
|
|
|
|
case "${1:-}" in
|
|
items)
|
|
feed=$(fetch_feed "${2:-50}")
|
|
titles=$(echo "$feed" | grep -oP '<title>\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 -"${2:-50}"
|
|
;;
|
|
article)
|
|
[ -z "${2:-}" ] && { echo "Usage: derstandard article <url>"; exit 1; }
|
|
fetch_single_article "$2"
|
|
;;
|
|
articles)
|
|
[ -z "${2:-}" ] && { echo "Usage: derstandard articles <url1,url2,...>"; exit 1; }
|
|
IFS=',' read -ra URLS <<< "$2"
|
|
for url in "${URLS[@]}"; do
|
|
# Extract title from URL slug
|
|
title=$(echo "$url" | grep -oP '/\d+/\K[^?]+' | tr '-' ' ' | sed 's/.*/\u&/')
|
|
echo "=== ${title} ==="
|
|
fetch_single_article "$url"
|
|
echo ""
|
|
echo ""
|
|
done
|
|
;;
|
|
urls)
|
|
fetch_feed "${2:-50}" | grep -oP '<link>\K[^<]+' | grep "derstandard.at/story"
|
|
;;
|
|
titles)
|
|
fetch_feed "${2:-50}" | grep -oP '<title>\K[^<]+' | tail -n +2 | decode_entities
|
|
;;
|
|
raw)
|
|
fetch_feed "${2:-50}"
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|