Compare commits
25 commits
Author | SHA1 | Date | |
---|---|---|---|
426253b09c | |||
920ec231c3 | |||
62b046e08b | |||
9ce0ef483c | |||
9ba9b9cc8c | |||
c2f8e8e028 | |||
70b7e79e6a | |||
4ea18d12cc | |||
f115b2ac50 | |||
ba6f13bf02 | |||
862e5898ad | |||
e2be96f26d | |||
07c2468f3b | |||
b8e899e3d9 | |||
f2c47e46f7 | |||
6fc67f285a | |||
1ee00554e4 | |||
a258a857cb | |||
c163dbf9c7 | |||
5ecd464fbe | |||
a8517d5733 | |||
f451b07764 | |||
6535237f6d | |||
812f1bfe51 | |||
053891690e |
2 changed files with 131 additions and 36 deletions
|
@ -77,10 +77,9 @@ If `MF_DEBUG` is set to `1`, `miniflux-filter` will print extra output to stdou
|
|||
|
||||
| RC | Description |
|
||||
| --- | ------------------------------- |
|
||||
| 1 | `$MF_FILTERLIST_FILE` not found |
|
||||
| 1 | `$MF_FILTERLIST` not set |
|
||||
| 2 | `$MF_AUTH_TOKEN` not set |
|
||||
| 3 | `$MF_API_URL` not set |
|
||||
| 4 | `$MF_FILTERLIST_FILE` is a dir |
|
||||
| 5 | `jq` is not installed |
|
||||
| 6 | `curl` is not installed |
|
||||
| 7 | could not connect to `miniflux` |
|
||||
|
|
164
filter.sh
164
filter.sh
|
@ -5,9 +5,7 @@ if [[ $MF_DEBUG -eq 1 ]]; then
|
|||
printf "miniflux-filter - git.mgrote.net/mg/miniflux-filter\n"
|
||||
fi
|
||||
|
||||
### datei mit filter ausdruecken
|
||||
MF_FILTERLIST_FILE="${MF_FILTERLIST_FILE:=/data/filter.txt}"
|
||||
### wartezeit zwischen durchlaeufen
|
||||
### wartezeit zwischen laeufen
|
||||
MF_SLEEP="${MF_SLEEP:=30}"
|
||||
### MF_DEBUG output
|
||||
# standardmäßig 0 = aus
|
||||
|
@ -25,7 +23,6 @@ Usage:
|
|||
|
||||
Options:
|
||||
-h, --help displays this text
|
||||
* script gets executed
|
||||
|
||||
EOF
|
||||
}
|
||||
|
@ -84,17 +81,11 @@ function check_vars {
|
|||
echo [ERROR] '"$MF_API_URL"' not set.
|
||||
exit 3
|
||||
fi
|
||||
# prüfe ob filter-datei ein ordner ist
|
||||
# kann bei einem falschen bind-mount passieren
|
||||
if [[ -d "$MF_FILTERLIST_FILE" ]]; then
|
||||
# shellcheck disable=SC2102
|
||||
echo [ERROR] "$MF_FILTERLIST_FILE" is a directory!
|
||||
exit 4
|
||||
fi
|
||||
# pruefe ob filter-datei NICHT existiert
|
||||
if [[ ! -e "$MF_FILTERLIST_FILE" ]]; then
|
||||
if [[ -z "${MF_FILTERLIST}" ]]; then
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2102
|
||||
echo [ERROR] "$MF_FILTERLIST_FILE" not readable!
|
||||
echo [ERROR] '"$MF_FILTERLIST"' not set.
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -142,11 +133,9 @@ function check_api_connectivity {
|
|||
function debug_output {
|
||||
if [[ $MF_DEBUG -eq 1 ]]; then
|
||||
echo -----------------------------------------------------
|
||||
echo [DEBUG] Filterlist-File: "$MF_FILTERLIST_FILE"
|
||||
echo [DEBUG] Sleep-Intervall: "$MF_SLEEP"
|
||||
echo [DEBUG] Auth-Token: "$MF_AUTH_TOKEN"
|
||||
echo [DEBUG] MF-Url: "$MF_API_URL"
|
||||
echo [DEBUG] Anzahl Filter: "$(wc -l < "$MF_FILTERLIST_FILE")"
|
||||
echo [DEBUG] MF-URL: "$MF_API_URL"
|
||||
echo -----------------------------------------------------
|
||||
fi
|
||||
}
|
||||
|
@ -165,8 +154,8 @@ function get_unread_entries {
|
|||
}
|
||||
function filter_entries {
|
||||
echo "[INFO] Filtering entries..."
|
||||
# fuer jede Zeile in $MF_FILTERLIST_FILE
|
||||
while read -r line; do
|
||||
# fuer jede Zeile in $MF_FILTERLIST
|
||||
echo "$MF_FILTERLIST" | while read -r line; do
|
||||
if [[ $MF_DEBUG -eq 1 ]]; then
|
||||
echo "[DEBUG] set search values"
|
||||
fi
|
||||
|
@ -189,42 +178,70 @@ function filter_entries {
|
|||
fi
|
||||
# das leerzeichen am anfang ist notwendig, trennt die zahlenwerte
|
||||
# suche in titel
|
||||
marked_entries+=" $(echo "$unread_entries" | jq --arg url "$url" --arg suchbegriff "$suchbegriff" '.entries[] | select(.feed.site_url | ascii_downcase | contains($url)) | select(.title | ascii_downcase | contains($suchbegriff)) | .id' )"
|
||||
titles+=" $(echo "$unread_entries" | jq --arg url "$url" --arg suchbegriff "$suchbegriff" '.entries[] | select(.feed.site_url | ascii_downcase | contains($url)) | select(.title | ascii_downcase | contains($suchbegriff)) | .id' )"
|
||||
# suche in content
|
||||
marked_entries+=" $(echo "$unread_entries" | jq --arg url "$url" --arg suchbegriff "$suchbegriff" '.entries[] | select(.feed.site_url | ascii_downcase | contains($url)) | select(.content | ascii_downcase | contains($suchbegriff)) | .id' )"
|
||||
content+=" $(echo "$unread_entries" | jq --arg url "$url" --arg suchbegriff "$suchbegriff" '.entries[] | select(.feed.site_url | ascii_downcase | contains($url)) | select(.content | ascii_downcase | contains($suchbegriff)) | .id' )"
|
||||
fi
|
||||
fi
|
||||
done < "$MF_FILTERLIST_FILE"
|
||||
# sortiere und forme marked_entries um
|
||||
marked_entries="$title $content"
|
||||
# https://unix.stackexchange.com/questions/353321/remove-all-duplicate-word-from-string-using-shell-script
|
||||
# entfernt doppelte eintraege innerhalb einer zeile
|
||||
marked_entries=$(echo marked_entries | xargs -n1 | sort -u | xargs | sed -r 's/\s/\, /g')
|
||||
echo "$marked_entries" #d
|
||||
done
|
||||
}
|
||||
function mark_as_read {
|
||||
# https://stackoverflow.com/questions/3869072/test-for-non-zero-length-string-in-bash-n-var-or-var
|
||||
# wenn variabler NICHT leer...
|
||||
# wenn variable NICHT leer...
|
||||
# sende in put request mit curl
|
||||
# der wert muss escaped werden, aber NICHT die variable die uebergeben wird
|
||||
if [[ $MF_DEBUG -eq 1 ]]; then
|
||||
echo "[DEBUG] mark entries as read"
|
||||
echo "[DEBUG] marked entry ids:"
|
||||
# https://unix.stackexchange.com/questions/353321/remove-all-duplicate-word-from-string-using-shell-script
|
||||
# entfernt doppelte eintraege innerhalb einer zeile
|
||||
echo "$marked_entries" | xargs -n1 | sort -u | xargs | sed -r 's/\s/\, /g'
|
||||
echo "$marked_entries"
|
||||
fi
|
||||
# wenn NICHT leer
|
||||
# sed wandelt 123 345 456 in 123, 245, 345 um.
|
||||
if [[ $(echo "$marked_entries" | xargs -n1 | sort -u | xargs | sed -r 's/\s/\, /g') ]]; then
|
||||
curl --request PUT --silent --header "X-Auth-Token: $MF_AUTH_TOKEN" --header "Content-Type: application/json" --data "{\"entry_ids\": [$(echo "$marked_entries" | xargs -n1 | sort -u | xargs | sed -r 's/\s/\, /g')], \"status\": \"read\"}" "$MF_API_URL/entries"
|
||||
# gebe entry-titel aus
|
||||
for i in $(echo "$marked_entries" | xargs -n1 | sort -u | xargs); do
|
||||
# gebe aus welcher eintrag gefiltert wurde, cut begrenzt die maximale laenge auf 100 zeichen
|
||||
# jq "XXX", fügt XXX in ausgabe hinzu
|
||||
echo [INFO] Filtered entry "$i" - "$(curl --silent --header "X-Auth-Token: $MF_AUTH_TOKEN" "$MF_API_URL"/entries/"$i" | jq --join-output '"url: ",.feed.site_url," - title: ", .title' | cut -c -100)".
|
||||
done
|
||||
if [[ -n "$marked_entries" ]]; then
|
||||
curl --request PUT --silent --header "X-Auth-Token: $MF_AUTH_TOKEN" --header "Content-Type: application/json" --data "{"entry_ids":"$marked_entries"],"status":"read"}" "$MF_API_URL/entries"
|
||||
# gebe entry-titel aus
|
||||
for i in "$marked_entries" ; do
|
||||
# gebe aus welcher eintrag gefiltert wurde, cut begrenzt die maximale laenge auf 100 zeichen
|
||||
# jq "XXX", fügt XXX in ausgabe hinzu
|
||||
echo [INFO] Filtered entry "$i" - "$(curl --silent --header "X-Auth-Token: $MF_AUTH_TOKEN" "$MF_API_URL"/entries/"$i" | jq --join-output '"url: ",.feed.site_url," - title: ", .title' | cut -c -100)".
|
||||
done
|
||||
fi
|
||||
# setze variablen auf leer
|
||||
marked_entries=""
|
||||
}
|
||||
|
||||
|
||||
|
||||
# debug
|
||||
MF_FILTERLIST="
|
||||
golem.de::Anzeige
|
||||
golem.de::Aus dem Verlag:
|
||||
golem.de::Elon Musk
|
||||
golem.de::Fifa
|
||||
golem.de::Fussball
|
||||
golem.de::Fußball
|
||||
golem.de::(g+)
|
||||
golem.de::Golem Karrierewelt
|
||||
golem.de::PODCAST BESSER WISSEN:
|
||||
golem.de::Sonst noch was?
|
||||
golem.de::Star Trek:
|
||||
golem.de::Tech Talks:
|
||||
golem.de::Twitter
|
||||
golem.de::Wochenrückblick
|
||||
heise.de::Dienstag:
|
||||
heise.de::Die Produktwerker
|
||||
heise.de::Elon Musk
|
||||
heise.de::Ferris Talk
|
||||
heise.de::FIFA
|
||||
heise.de::Freitag
|
||||
heise.de::Fußball-WM
|
||||
heise.de::heise+
|
||||
"
|
||||
# Doing
|
||||
case "$1" in
|
||||
--help | -h | help)
|
||||
|
@ -245,3 +262,82 @@ case "$1" in
|
|||
sleep "$MF_SLEEP"
|
||||
done
|
||||
esac
|
||||
|
||||
|
||||
|
||||
# curl --request PUT --header "X-Auth-Token: hLPp23gO8QeZWPYXXXXXXXMs0jG0XTYgNZBgRA=" --header "Content-Type: application/json" --data '{"entry_ids":[388229, 388211], "status":"read"}' https://miniflux.mgrote.net/v1/entries
|
||||
|
||||
|
||||
|
||||
lese suchwörter per feedurl ein
|
||||
suche pro feed url nach suchwortern
|
||||
markiere als gelesen
|
||||
|
||||
|
||||
|
||||
|
||||
get all feeds where are unread entries+
|
||||
check if for that feeds a filter is defined
|
||||
search for keywords for this feedsunread entries
|
||||
mark entries as read
|
||||
|
||||
|
||||
token: hLPp23gO8QeZWPYzK3jYgmGbABvMs0jG0XTYgNZBgRA= # später tauschen
|
||||
|
||||
|
||||
curl -H "X-Auth-Token: hLPp23gO8QeZWPYzK3jYgmGbABvMs0jG0XTYgNZBgRA=" https://miniflux.mgrote.net/v1/me
|
||||
|
||||
|
||||
#!/bin/bash
|
||||
# get all feeds where are unread entries+
|
||||
|
||||
token="X-Auth-Token: hLPp23gO8QeZWPYzK3jYgmGbABvMs0jG0XTYgNZBgRA="
|
||||
url="https://miniflux.mgrote.net/v1/"
|
||||
for feed in $(curl --silent -H $token $url/feeds | jq .[].id) ; do
|
||||
unread_entries=$(curl --silent -H $token $url/feeds/$feed/entries?status=unread)
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
----
|
||||
#!/bin/bash
|
||||
# get all feeds where are unread entries+
|
||||
|
||||
MF_FILTERLIST="
|
||||
golem.de::Anzeige
|
||||
golem.de::Aus dem Verlag:
|
||||
golem.de::Elon Musk
|
||||
golem.de::Fifa
|
||||
golem.de::Fussball
|
||||
golem.de::Fußball
|
||||
golem.de::(g+)
|
||||
"
|
||||
|
||||
token="X-Auth-Token: hLPp23gO8QeZWPYzK3jYgmGbABvMs0jG0XTYgNZBgRA="
|
||||
url="https://miniflux.mgrote.net/v1"
|
||||
|
||||
# für jeden feed
|
||||
for feed in $(curl --silent -H "$token" "$url/feeds" | jq .[].id) ; do
|
||||
echo for1
|
||||
unread_entries=$(curl --silent -H "$token" "$url/feeds/$feed/entries?status=unread" | jq .total)
|
||||
# der ungelesen einträge hat
|
||||
if [[ $unread_entries -gt 0 ]] ; then
|
||||
echo if1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$MF_FILTERLIST" | while read -r line ; do
|
||||
echo while1
|
||||
filter_url=$(echo "$line" | tr '[:upper:]' '[:lower:]' | awk --field-separator="::" '{print $1}')
|
||||
echo $filter_url
|
||||
mf_site_url=$(curl --silent -H "$token" "$url/feeds/$feed" | jq --raw-output .site_url)
|
||||
echo $mf_site_url
|
||||
# prufe ob ein filter dafur existiert
|
||||
echo "$filter_url" | grep "$mf_site_url"
|
||||
if [[ $(echo "$filter_url" | grep --silent "$mf_site_url") ]] ; then
|
||||
echo for2
|
||||
echo "id: $feed"
|
||||
echo "$mf_site_url $filter_url"
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue