2 # pdt: post to FSF social media via command line
3 # Copyright (C) 2021 Ian Kelling
4 # SPDX-License-Identifier: AGPL-3.0-or-later
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # This is meant to be sourced.
21 PATH
="$HOME/.local/bin:$PATH"
23 # usage: rbow [-PROFILE_NAME] [COMMAND]
25 # Wrapper for rainbowstream to use multiple logins and tweet directly
26 # from the command line. PROFILE_NAME can be anything you want.
29 oath
=$HOME/.rainbow_oauth
30 if [[ $1 == -* ]]; then
35 source ~
/src
/rainbowstream
/venv
/bin
/activate
39 # adds a short delay after each send for more reliable operation
40 set force_conservative 1
43 expect -nocase timeout {exit 1} "@*]: "
44 set cmd [lindex $argv 0];
46 expect -nocase timeout {exit 1} "@*]: "
47 # this may not be needed. didnt test
52 expect
$f "$*" ||
{ echo error
: expect failed
; deactivate
; rm -f $f; return 1; }
61 source ~
/src
/diaspy
/venv
/bin
/activate
62 python3 ~
/src
/jan-pona-mute
/jan-pona-mute.py
"$@" ||
{ deactivate
; return 1; }
66 # usage: toot [-PROFILE_NAME] [TOOT_ARGS]
69 source ~
/src
/toot
/venv
/bin
/activate
70 if [[ $1 == -* ]]; then
73 command toot activate
--quiet $account ||
{ deactivate
; return 1; }
75 command toot
"$@" ||
{ deactivate
; return 1; }
80 # post to mastodon + twitter + gnu social post + diaspora
82 # usage: pdt [--dbd] [-m MEDIA_FILE] [-v VIDEO_PATH] [POST]
84 local video media rbow_account gs_account mastodon_account dbd video rbow_arg toot_arg dia_arg gs_arg
85 if [[ $pdttest ]]; then
88 mastodon_account
=iank@hostux.social
92 mastodon_account
=fsf@hostux.social
96 while [[ $1 == -* ]]; do
101 rbow_arg
=" --i $media"
102 toot_arg
="--media $media"
104 gs_arg
="-F media=@$media"
110 mastodon_account
=endDRM@hostux.social
120 if [[ $media ]]; then
121 if [[ ! -e $media ]]; then
122 echo "error: file not found $media"
125 if [[ $media == *\
* ]]; then
126 echo "error: file path contains a space. move it to non-space path"
130 # if we have no argument
132 read -r -p "input PDT text: " input
135 if [[ $
- == *i
* ]]; then
136 echo "About to PDT the following line. Press enter to confirm or ctrl-c to quit:"
142 oath
=$HOME/.rainbow_oauth
148 ln -s ${oath}-$account $oath
149 python3 ~
/src
/video-tweet
/async-upload.py
"$media" "$*"
153 if ! rbow
-$rbow_account t
"$*" $rbow_arg; then
156 if ! toot
-$mastodon_account post
"$*" $toot_arg; then
160 if ! printf "post %s\n" "${dia_arg}$*" | diaspora
; then
164 # https://gnusocial.net/doc/twitterapi
165 if ! curl
-o /dev
/null
-sS -u "$gs_account:$(cat ~/.gnusocial_login-$gs_account)" \
166 $gs_arg -F "status=$*" https
://status.fsf.org
/api
/statuses
/update.xml
; then
169 if (( ${#fails[@]} )); then
170 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}"); echo
171 echo "FSF ERROR: ${fails[*]} might not have posted" >&2
177 if [[ $pdttest ]]; then
178 mastodon_accounts
=(iank
)
180 mastodon_accounts
=(fsf endDRM
)
185 for repo
in errhandle rainbowstream diaspy jan-pona-mute video-tweet
; do
186 if [[ -e $repo ]]; then
189 git
reset --hard origin
/master
193 git clone https
://vcs.fsf.org
/git
/$repo.git
196 source ~
/src
/errhandle
/err
197 cp ~
/src
/rainbowstream
/rainbowstream
/colorset
/config ~
/.rainbow_config.json
199 if [[ ! -e ~
/.local
/bin
/pip
]]; then
201 wget
-O$tmp https
://bootstrap.pypa.io
/get-pip.py
207 if [[ ! -e ~
/.local
/bin
/virtualenv
]]; then
208 python3
-m pip
install --user virtualenv
211 cd ~
/src
/rainbowstream
212 python3
-m virtualenv
-p python3 venv
213 source venv
/bin
/activate
214 python3
-m pip
install -r requirements.txt
215 python3
-m pip
install -e .
219 # This repo's upstream is https://alexschroeder.ch/cgit/diaspy which is
220 # recommended in the install instructions here:
221 # https://alexschroeder.ch/cgit/jan-pona-mute/about/
223 python3
-m virtualenv
-p python3 venv
224 source venv
/bin
/activate
225 python3
-m pip
install -r requirements.txt
226 python3
-m pip
install -e .
232 python3
-m virtualenv
-p python3 venv
233 source venv
/bin
/activate
234 # pip freeze after a pip install.
235 cat >requirements.txt
<<'EOF'
236 beautifulsoup4==4.8.2
247 python3
-m pip
install -r requirements.txt
251 if [[ ! -s ~
/.config
/jan-pona-mute
/login
]]; then
252 mkdir ~
/.config
/jan-pona-mute
253 account
=fsf@framasphere.org
254 read -r -p "enter the password for $account > " pass
255 # background: format for this found using the save command
256 cat >~
/.config
/jan-pona-mute
/login
<<EOF
263 for account
in dbd fsf
; do
264 if [[ ! -s ~
/.rainbow_oauth-
$account ]]; then
265 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
266 echo "Please login to $account on twitter in your main browser then press enter. After rainbowstream prompt loads, quit with command q"
270 if [[ ! -s ~
/.gnusocial_login-
$account ]]; then
271 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
272 read -r -p "please enter the password for $account@status.fsf.org > " pass
273 touch ~
/.gnusocial_login-
$account
274 chmod 600 ~
/.gnusocial_login-
$account
275 printf "%s\n" "$pass" > ~
/.gnusocial_login-
$account
279 for account
in ${mastodon_accounts[@]}; do
280 if ! toot activate
$account@hostux.social
&>/dev
/null
; then
281 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
282 echo "Please login to $account on https://hostux.social in your main browser then press enter."
284 toot login
-i hostux.social