-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: shell-mastodon-api action: commit revision: path_from: revision_from: e142baa50bf7e71c656294ab4833c433ed776bce: path_to: revision_to:
commit e142baa50bf7e71c656294ab4833c433ed776bce Author: epoch <epoch@thebackupbox.net> Date: Wed Jul 20 07:42:38 2022 +0000 it is in a workable state without my own data left inside scripts. I think diff --git a/home.sh b/home.sh new file mode 100755 index 0000000000000000000000000000000000000000..535ebc186d8ee410c06f351b2d8218f1e914c4d3 --- /dev/null +++ b/home.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +### this outputs your home-feed. one post per line. + +BEARER="$(cat ~/.config/mastodon.bearer 2>/dev/null)" +HOME_INSTANCE="$(cat ~/.config/mastodon.home 2>/dev/null)" + +if [ "$1" = "--clear" ];then + rm ~/.cache/mastodon/since_id +fi + +if [ ! "$BEARER" ];then + printf "create a bearer token and place it in ~/.config/mastodon.env" +fi + +since_id="$(cat ~/.cache/mastodon/since_id 2>/dev/null)" + +if [ "$since_id" ];then + since_id="?since_id=${since_id}" +fi + +curl -sH "Authorization: Bearer ${BEARER}" -g "${HOME_INSTANCE}/api/v1/timelines/home${since_id}" \ + | jq -c '.[]' diff --git a/post-handler.sh b/post-handler.sh new file mode 100755 index 0000000000000000000000000000000000000000..952e70df2575747af07292201a526435b14de203 --- /dev/null +++ b/post-handler.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +### this reads one post per line on stdin. +### and uses notify-send to send it as a desktop notification + +first=yeah + +while read -r post;do + +att_list="" + +if [ "$first" == "yeah" ];then + first=nah + printf "%s\n" "$post" | jq -r '.id' > ~/.cache/mastodon/since_id +fi + +printf '%s----BEGIN POST-----\n' "-" + +acct="$(printf "%s\n" "$post" | jq -r '.account.acct//""')" +content="$(printf "%s\n" "$post" | jq -r '.content//""' | w3m -T text/html -dump)" +reblog_acct="$(printf "%s\n" "$post" | jq -r '.reblog.account.acct//""')" +reblog_content="$(printf "%s\n" "$post" | jq -r '.reblog.content//""' | w3m -T text/html -dump)" +spoiler_text="$(printf "%s\n" "$post" | jq -r '.spoiler_text//""')" +avatar_url="$(printf "%s\n" "$post" | jq -r '.account.avatar//""')" + +printf "acct: %s\n" "$acct" +printf "content: %s\n" "$content" +printf "reblog_acct: %s\n" "$reblog_acct" +printf "reblog_content: %s\n" "$reblog_content" +printf "spoiler_text: %s\n" "$spoiler_text" +printf "media_attachments:\n" +att_list="$(printf "%s\n" "$post" | jq -c '.media_attachments[]' | while read at;do + att_url="$(printf "%s\n" "$at" | jq -r '.url' )" + printf " [att] %s\n" "$att_url" +done)" +printf '%s\n' "$att_list" + +if [ "${reblog_content}" ];then + content="reblog of ${reblog_acct}"$'\n'"${reblog_content}" +fi + +if [ "${spoiler_text}" ];then + content="CW: ${spoiler_text}"$'\n'"${content}" +fi + +if [ "${att_list}" ];then + content="${content}"$'\n'"${att_list}" +fi + +avatar_cache_file=~/.cache/mastodon/avatar_"${acct}" + +rfc7231date="" ## $(which rfc7231date)" ## this program is in another repo of mine, not /that/ important to this script. +## work left to the reader to decide if they want to track it down and go to original behavior + +if [ ! "${rfc7231date}" ];then # if we do not have this program, fallback to only checking for file existence. + if [ ! -e "${avatar_cache_file}" ];then + curl -s \ + -g "$avatar_url" \ + -o "${avatar_cache_file}" + fi +else + curl -s \ + -H "If-Modified-Since: $(rfc7231date "$(stat -c '%Y' "${avatar_cache_file}")")" \ + -g "$avatar_url" \ + -o "${avatar_cache_file}" +fi + +notify-send -i "${avatar_cache_file}" "fediverse post by \"$acct\"" "${content}" + +printf '%s----END POST-----\n' "-" + +done
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 11:15:32 2024