Add several arguments: -b, -B, -t, and -l

This commit is contained in:
Jaidyn Ann 2024-04-22 01:50:22 -05:00
parent c5e9a5bc93
commit 9fe6003f6c

View File

@ -203,8 +203,12 @@ fetch_post() {
fetch_user_posts() { fetch_user_posts() {
local url="$1" local url="$1"
local server="$(url_server "$url")" local server="$(url_server "$url")"
local status_url="$server/api/v1/accounts/$(url_user_id "$url")/statuses"
status_url="${status_url}?exclude_reblogs=${EXCLUDE_REBLOGS}&limit=$MAX_POSTS"
status_url="${status_url}&exclude_replies=${EXCLUDE_REPLIES}$TAG_FILTER"
curl --location --header 'Accept: application/json,application/activity+json' \ curl --location --header 'Accept: application/json,application/activity+json' \
"$server/api/v1/accounts/$(url_user_id "$url")/statuses?exclude_reblogs" \ "$status_url" \
| jq -c '.[]' | jq -c '.[]'
} }
@ -335,27 +339,39 @@ handle_post_url() {
usage() { usage() {
echo "usage: $(basename "$0") [-h] [-IR] POST_URL" echo "usage: $(basename "$0") [-h] [-IRc] POST_URL"
echo " $(basename "$0") [-h] [-IRc] [-bBt] USER_URL"
echo echo
echo "$(basename "$0") does exactly what it says on the tin: It formats" echo "$(basename "$0") does exactly what it says on the tin: It formats"
echo "a fediverse post (and its replies) into simple-and-embeddable HTML." echo 'a fediverse post (and its replies) into simple-and-embeddable HTML.'
echo echo
echo "It works with posts from any server that supports Mastodons API," echo 'It works with posts from any server that supports Mastodons API,'
echo "including Pleroma, Akkoma, Glitch, etc." echo 'including Pleroma, Akkoma, Glitch, etc.'
echo echo
echo "Notably, it supports post-atachments and custom-emoji. Keep in mind" echo 'Notably, it supports post-atachments and custom-emoji. Keep in mind'
echo "that images are all fetched from remote sources. It is recommended," echo 'that images are all fetched from remote sources. It is recommended,'
echo "if privacy or total archival, is a concern, to use wget(1)s --mirror" echo 'if privacy or total archival, is a concern, to use wget(1)s --mirror'
echo "(or something like it) to fetch even these foreign files." echo '(or something like it) to fetch even these foreign files.'
echo echo
echo " -c only print the responses (children) of a post" echo ' -c only print the responses (children) of a post'
echo " -h print this message and exit" echo ' -h print this message and exit'
echo " -I display posts in reverse-chronological order" echo ' -I display posts in reverse-chronological order'
echo " -R do not recursively display posts responses" echo ' -l output at maximum the specified amount of posts'
echo ' -R do not recursively display posts responses'
echo
echo ' -b exclude reblogs/repeats from user feed'
echo ' -B exclude top-level replies from user feed'
echo ' -t filter posts from user feed by tag'
} }
while getopts 'hcIR' arg; do TAG_FILTER=""
EXCLUDE_REPLIES="false"
EXCLUDE_REBLOGS="false"
MAX_POSTS=20
while getopts 'hcIRt:bm:B' arg; do
case $arg in case $arg in
h) h)
usage usage
@ -370,6 +386,18 @@ while getopts 'hcIR' arg; do
R) R)
NO_RESPONSES="1" NO_RESPONSES="1"
;; ;;
t)
TAG_FILTER="&tagged=$OPTARG"
;;
b)
EXCLUDE_REBLOGS="true"
;;
m)
MAX_POSTS="$OPTARG"
;;
B)
EXCLUDE_REPLIES="true"
;;
esac esac
done done
@ -383,17 +411,14 @@ if test -z "$URL"; then
fi fi
USER_ID="$(url_user_id "$URL")" USER_ID="$(url_user_id "$URL")"
POST_ID="$(url_post_id "$URL")" POST_ID="$(url_post_id "$URL")"
if test -n "$POST_ID"; then if test -n "$POST_ID"; then
echo "POST"
handle_post_url "$URL" handle_post_url "$URL"
elif test -n "$USER_ID"; then elif test -n "$USER_ID"; then
handle_user_url "$URL" handle_user_url "$URL"
else else
echo "That URL is not recognized as a post or user URL." 1>&2 echo 'That URL is not recognized as a post or user URL.' 1>&2
exit 3 exit 3
fi fi