From 9667049be39eb1f54f5f80432a0370395340567c Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 29 Nov 2022 00:19:08 -0500 Subject: [PATCH] add alt text for mastodon upgrade by running toot-setup I also think i fixed a bug or two along the way --- pdt.sh | 240 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 165 insertions(+), 75 deletions(-) diff --git a/pdt.sh b/pdt.sh index f6a3505..acf6fe1 100644 --- a/pdt.sh +++ b/pdt.sh @@ -59,12 +59,12 @@ EOF # usage: toot [-PROFILE_NAME] [TOOT_ARGS] toot() { - local account + local mast_profile source ~/src/toot/venv/bin/activate if [[ $1 == -* ]]; then - account=${1#-} + mast_profile=${1#-} shift - command toot activate --quiet $account || { deactivate; return 1; } + command toot activate --quiet $mast_profile || { deactivate; return 1; } fi command toot "$@" || { deactivate; return 1; } deactivate @@ -76,13 +76,17 @@ toot() { # If posting video, it only goes to twitter. Other accounts can be # posted to manually with free software. # -# usage: pdt [--dbd] [-m MEDIA_FILE] [-v VIDEO_PATH] [POST] +# Alt text only goes to mastodon. +# +# usage: pdt [-s mastodon|twitter|gnusocial] [--dbd] [-m MEDIA_FILE] [-a ALT_TEXT] [-v VIDEO_PATH] [POST] +# -s = post to single social network supplied by argument. pdt() { - local video media rbow_account gs_account mastodon_account dbd video rbow_arg toot_arg dia_arg gs_arg + local video media rbow_account gs_account mastodon_account dbd video rbow_arg gs_arg alt_text + local -a toot_args if [[ $pdttest ]]; then rbow_account=iank gs_account=fsfes - mastodon_account=iank@hostux.social + mastodon_account=fsftest@hostux.social else rbow_account=fsf gs_account=fsf @@ -90,14 +94,43 @@ pdt() { fi dbd=false video=false + do_mastodon=true + do_twitter=true + do_gnusocial=true while [[ $1 == -* ]]; do case $1 in + -s) + network="$2" + do_mastodon=false + do_twitter=false + do_gnusocial=false + case $network in + mastodon) + do_mastodon=true + ;; + twitter) + do_twitter=true + ;; + gnusocial) + do_gnusocial=true + ;; + *) + echo "pdt: error: expected -s mastodon|twitter|gnusocial" + return 1 + ;; + esac + shift 2 + ;; + -a) + alt_text="$2" + toot_args+=(--description "$alt_text" ) + shift 2 + ;; -m) media="$2" shift 2 rbow_arg=" --i $media" - toot_arg="--media $media" - dia_arg="-p $media " + toot_args+=(--media "$media" ) gs_arg="-F media=@$media" ;; --dbd) @@ -131,32 +164,34 @@ pdt() { fi if [[ $- == *i* ]]; then echo "About to PDT the following line. Press enter to confirm or ctrl-c to quit:" - echo "$input" - read + echo "$*" + read -r fi if $video; then local oath oath=$HOME/.rainbow_oauth - account=fsf - if $dbd; then - account=dbd - fi rm -f $oath - ln -s ${oath}-$account $oath + ln -s ${oath}-$rbow_account $oath python3 ~/src/video-tweet/async-upload.py "$media" "$*" return fi fails=() - if ! rbow -$rbow_account t "$*" $rbow_arg; then - fails+=(tweet) + if $do_twitter; then + if ! rbow -$rbow_account t "$*" $rbow_arg; then + fails+=(tweet) + fi fi - if ! toot -$mastodon_account post "$*" $toot_arg; then - fails+=(toot) + if $do_mastodon; then + if ! toot -$mastodon_account post "$*" "${toot_args[@]}"; then + fails+=(toot) + fi fi - # https://gnusocial.net/doc/twitterapi - if ! curl -o /dev/null -sS -u "$gs_account:$(cat ~/.gnusocial_login-$gs_account)" \ - $gs_arg -F "status=$*" https://status.fsf.org/api/statuses/update.xml; then - fails+=(gnu-social) + if $do_gnusocial; then + # https://gnusocial.net/doc/twitterapi + if ! curl -o /dev/null -sS -u "$gs_account:$(cat ~/.gnusocial_login-$gs_account)" \ + $gs_arg -F "status=$*" https://status.fsf.org/api/statuses/update.xml; then + fails+=(gnu-social) + fi fi if (( ${#fails[@]} )); then printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); echo @@ -164,14 +199,106 @@ pdt() { fi } -# Usage: pdt-setup -pdt-setup() { +# Usage: toot-setup +# +# Only run manually for testing. +# +# this expects pdt-pip-setup has been run already, and it doesn't setup +# errhandle. +# +# note: auth info is stored at ~/.config/toot/config.json +toot-setup() { if [[ $pdttest ]]; then - mastodon_accounts=(iank) + mastodon_accounts=(fsftest) else mastodon_accounts=(fsf endDRM) fi + rm -rf ~/src/toot + mkdir -p ~/src/toot + cd ~/src/toot + # on t11, got myself into a situation where when doing pip install virtualenv, + # it gave an error that /usr/bin/pip didn't exist, so i did + # sudo ln -s /home/iank/.local/bin/pip /usr/bin + # + python3 -m virtualenv -p python3 venv + source venv/bin/activate + # pip freeze after a pip install, as of 2022-11-28 + cat >requirements.txt <<'EOF' +beautifulsoup4==4.11.1 +certifi==2022.9.24 +charset-normalizer==2.1.1 +idna==2.8 +requests==2.22.0 +soupsieve==2.3.2.post1 +toot==0.29.0 +urllib3==1.25.8 +urwid==2.1.2 +wcwidth==0.2.5 +EOF + + # new 2022-11 packages + # beautifulsoup4==4.11.1 + # certifi==2022.9.24 + # charset-normalizer==2.1.1 + # idna==3.4 + # requests==2.28.1 + # soupsieve==2.3.2.post1 + # toot==0.29.0 + # urllib3==1.26.13 + # urwid==2.1.2 + # wcwidth==0.2.5 + + # old 2019 packages + # beautifulsoup4==4.8.2 + # certifi==2019.11.28 + # chardet==3.0.4 + # idna==2.8 + # requests==2.22.0 + # soupsieve==1.9.5 + # toot==0.25.2 + # urllib3==1.25.8 + # urwid==2.1.0 + # wcwidth==0.1.8 + + # i mixed in some old packages to get newer toot working on t9. + + python3 -m pip install -r requirements.txt + deactivate + for account in ${mastodon_accounts[@]}; do + if ! toot activate $account@hostux.social &>/dev/null; then + printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); + echo "Please login to the account named \"$account\" on https://hostux.social in your main browser then press enter." + echo "WARNING: if you log into an account other than \"$account\", this won't work" + read -r + toot login -i hostux.social + fi + done +} + +# Usage: pdt-pip-setup +pdt-pip-setup() { + if [[ ! -e ~/.local/bin/pip ]]; then + tmp=$(mktemp) + pyver=$(python3 --version | sed -r 's/.*(3\.[0-9]+).*/\1/') + echo fyi: detected pyver: $pyver. this should look something like 3.6 + + if dpkg --compare-versions 3.6 ge $pyver; then + # The bootstrap script at https://bootstrap.pypa.io/get-pip.py required 3.7+ + # when i wrote this. + wget -O$tmp https://bootstrap.pypa.io/pip/$pyver/get-pip.py + else + wget -O$tmp https://bootstrap.pypa.io/get-pip.py + fi + python3 $tmp --user + hash -r + fi + python3 -m pip install --user -U virtualenv +} + +# Usage: pdt-setup +pdt-setup() { + mkdir -p ~/src cd ~/src for repo in errhandle rainbowstream video-tweet; do @@ -188,18 +315,9 @@ pdt-setup() { source ~/src/errhandle/err cp ~/src/rainbowstream/rainbowstream/colorset/config ~/.rainbow_config.json - if [[ ! -e ~/.local/bin/pip ]]; then - tmp=$(mktemp) - pyver=$(python3 --version | sed -r 's/.*(3\.[0-9]+).*/\1/') - echo fyi: detected pyver: $pyver. this should look something like 3.6 - # the bootstrap script at https://bootstrap.pypa.io/get-pip.py requires 3.7+ - # as I write this. - wget -O$tmp https://bootstrap.pypa.io/pip/$pyver/get-pip.py - python3 $tmp --user - hash -r - fi + pdt-pip-setup - python3 -m pip install --user -U virtualenv + toot-setup cd ~/src/rainbowstream python3 -m virtualenv -p python3 venv @@ -208,28 +326,6 @@ pdt-setup() { python3 -m pip install -e . deactivate - - rm -rf ~/src/toot - mkdir -p ~/src/toot - cd ~/src/toot - python3 -m virtualenv -p python3 venv - source venv/bin/activate - # pip freeze after a pip install. - cat >requirements.txt <<'EOF' -beautifulsoup4==4.8.2 -certifi==2019.11.28 -chardet==3.0.4 -idna==2.8 -requests==2.22.0 -soupsieve==1.9.5 -toot==0.25.2 -urllib3==1.25.8 -urwid==2.1.0 -wcwidth==0.1.8 -EOF - python3 -m pip install -r requirements.txt - deactivate - for account in dbd fsf; do if [[ ! -s ~/.rainbow_oauth-$account ]]; then printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); @@ -237,17 +333,19 @@ EOF read -r rbow -$account fi - for account in dbd fsf; do - if [[ ! -s $HOME/.rainbow_oauth-$account ]]; then - echo "pdt-setup error: expected non-empty file at $HOME/.rainbow_oauth-$account by this point. please fix and rerun pdt-setup or contact ian" - return 1 - fi - done - if diff -q $HOME/.rainbow_oauth-fsf $HOME/.rainbow_oauth-dbd &>/dev/null; then - echo "pdt-setup error: error, $HOME/.rainbow_oauth-fsf $HOME/.rainbow_oauth-dbd are the same. Did you follow the instructions closely and log into fsf and then dbd when prompted? try reruning pdt-setup and doing that" + done + for account in dbd fsf; do + if [[ ! -s $HOME/.rainbow_oauth-$account ]]; then + echo "pdt-setup error: expected non-empty file at $HOME/.rainbow_oauth-$account by this point. try reruning pdt-setup and logging in to the correct twitter account in browser or contact ian" return 1 fi + done + if diff -q $HOME/.rainbow_oauth-fsf $HOME/.rainbow_oauth-dbd &>/dev/null; then + echo "pdt-setup error: error, $HOME/.rainbow_oauth-fsf $HOME/.rainbow_oauth-dbd are the same. Did you follow the instructions closely and log into fsf and then dbd when prompted? try reruning pdt-setup and doing that" + return 1 + fi + for account in dbd fsf; do if [[ ! -s ~/.gnusocial_login-$account ]]; then printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); read -r -p "please enter the password for $account@status.fsf.org > " pass @@ -257,14 +355,6 @@ EOF fi done - for account in ${mastodon_accounts[@]}; do - if ! toot activate $account@hostux.social &>/dev/null; then - printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); - echo "Please login to $account on https://hostux.social in your main browser then press enter." - read -r - toot login -i hostux.social - fi - done err-allow echo "pdt-setup complete" } -- 2.25.1